C# 按样式设置的工具提示无效

C# 按样式设置的工具提示无效,c#,wpf,data-binding,C#,Wpf,Data Binding,下面列表框的工具提示是使用setter设置的。鼠标悬停时,工具提示不会显示任何内容 我怀疑问题在于列表框本身的itemssource。列表框绑定到名为CandidateAttributes的属性项列表。该列表的一个元素是名为AttributePath的observablecollection,我试图将工具提示绑定到的属性路径中的属性名为ConceptualPath。以下是候选属性的定义- public static List<AttributeItem> CoBRRaAttribu

下面列表框的工具提示是使用setter设置的。鼠标悬停时,工具提示不会显示任何内容

我怀疑问题在于列表框本身的itemssource。列表框绑定到名为CandidateAttributes的属性项列表。该列表的一个元素是名为AttributePath的observablecollection,我试图将工具提示绑定到的属性路径中的属性名为ConceptualPath。以下是候选属性的定义-

 public static List<AttributeItem> CoBRRaAttributes { get; set; }
公共静态列表属性{get;set;}
AttributeItems类-

public class AttributeItem 
{
    private string _displayName = "";
            private ObservableCollection<CoBRRa_WPF.CoBRRaUtilities.ViewModels.QueryTool.AttributeCollection> _AttributePath;


    public AttributeItem(int id, string displayName, ObservableCollection<CoBRRa_WPF.CoBRRaUtilities.ViewModels.QueryTool.AttributeCollection> attributePath)
    {
        DisplayName = displayName;
        AttributePath = attributePath;

    }

    public ObservableCollection<CoBRRa_WPF.CoBRRaUtilities.ViewModels.QueryTool.AttributeCollection> AttributePath
    {
        get
        {
            return _AttributePath;
        }
        set
        {
            _AttributePath = value;
        }
    }
  }
公共类属性项
{
私有字符串_displayName=“”;
私人可观察收集(AttributePath);;
公共属性项(int-id、字符串显示名、ObservableCollection属性路径)
{
DisplayName=DisplayName;
AttributePath=AttributePath;
}
公共可观测集合属性路径
{
得到
{
返回属性路径;
}
设置
{
_属性路径=值;
}
}
}
圣诞节-

            <ListBox 
            Name="lstCandidates" 
            ItemsSource="{Binding Path=UIProperties.CandidateAttributes}"
            >
            <ListBox.ItemTemplate>            
                <DataTemplate>
                    <TextBlock Text="{Binding Path=DisplayName}">
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Control.ToolTip" Value="{Binding AttributePath.ConceptualPath}"/>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>


我可以替换一些文本来代替绑定AttributePath.ConceptualPath,工具提示会显示该文本。只是不明白为什么它在绑定中不起作用。我如何才能让它工作?

您正在绑定到
AttributePath。ConceptualPath
但是
AttributePath
返回一个
ObservableCollection
,而这个没有
ConceptualPath
属性

您应该将
AttributePath
属性的类型更改为just
CoBRRa_WPF.CoBRRaUtilities.ViewModels.QueryTool.AttributeCollection
,或者绑定到特定的
AttributeCollection
,例如第一个:

<Setter Property="Control.ToolTip" Value="{Binding AttributePath[0].ConceptualPath}"/>

AttributePath是一个集合。您要绑定此集合中的哪个项?可能有几个。ConceptualPath是我想要绑定到的。我认为行“Binding AttributePath.ConceptualPath”将填充工具提示,因为ConceptualPath是AttributePath集合的一个属性。我忽略了包含来自CoBRRa_WPF.CoBRRaUtilities.ViewModels.QueryTool.AttributeCollection的片段。将更新。否,attributePath返回一个ObservableCollection,此集合没有ConceptualPath属性。AttributePath是AttributeCollections的集合。这很有意义。已尝试AttributePath[0]。ConceptualPath但不起作用。我已验证ConceptualPath是AttributeCollection类的公共属性。AttributePath集合是否已填充?是否调试以找到答案?它已填充。事实上,通过将其放入样式中,然后将ItemsControl的ItemsSource指定为AttributePath,我确实部分实现了这一点。这种方法本身也有问题,但确实填充了工具提示。UIProperties.CandidateAttribute返回什么?请提供您的问题的MCVE:
<Style TargetType="{x:Type ListBoxItem}">
    <Setter Property="Control.ToolTip">
        <Setter.Value>
            <ItemsControl ItemsSource="{Binding AttributePath}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding ConceptualPath}" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Setter.Value>
    </Setter>
</Style>