【发布时间】:2019-01-18 03:56:34
【问题描述】:
以下列表框的工具提示是使用 setter 设置的。鼠标悬停时不会出现任何工具提示。
我怀疑问题出在列表框本身的 itemssource 上。列表框绑定到一个名为 CandidateAttributes 的 AttributeItems 列表。该列表的一个元素是一个名为 AttributePath 的 observablecollection,而我试图将工具提示绑定到的属性路径中的属性称为 ConceptualPath。以下是 CandidateAttributes 的定义-
public static List<AttributeItem> CoBRRaAttributes { 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;
}
}
}
xmal-
<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>
我可以用一些文本代替 Binding AttributePath.ConceptualPath,工具提示会显示该文本。只是无法弄清楚为什么它在绑定中不起作用。我怎样才能让它工作?
【问题讨论】:
-
AttributePath 是一个集合。您要绑定此集合中的哪个项目?可能有几个。
-
ConceptualPath 是我想要绑定的。认为“Binding AttributePath.ConceptualPath”行会填充工具提示,因为 ConceptualPath 是 AttributePath 集合的属性。我忽略了包含来自 CoBRRa_WPF.CoBRRaUtilities.ViewModels.QueryTool.AttributeCollection 的 sn-p。会更新。
-
不,attributePath 返回一个 ObservableCollection,而这个没有 ConceptualPath 属性。 AttributePath 是 AttributeCollections 的集合。
标签: c# wpf data-binding