【发布时间】:2014-11-03 12:54:25
【问题描述】:
我有一个 Silverlight 应用程序。
我需要向文本块添加一个工具提示,以显示有关其他元素(GridView)的信息
<ToolTipService.ToolTip>
<ToolTip>
<TextBlock x:Name="Test"
VerticalAlignment="Center"
FontSize="12"
Margin="10,0,0,0"
Foreground="DimGray"
Visibility="Visible">
<Run Text="{Binding Path=Items.Count,
ElementName=SearchResultsPresenter,
StringFormat=\{0:N0\}}"/>
<Run Text="{Binding
Source={StaticResource PublicResourceStrings},
Path=ResourceStrings.SEARCH_RESULTS_DISPLAYED}"/>
<Run Text="{Binding SelectedItems.Count,
ElementName=SearchResultsPresenter,
StringFormat=\{0:N0\}}"/>
<Run Text="{Binding
Source={StaticResource PublicResourceStrings},
Path=ResourceStrings.SEARCH_RESULTS_SELECTED}"/>
</TextBlock>
</ToolTip>
</ToolTipService.ToolTip>
但是与 elementName 的绑定不起作用。 Items.Count 和 SelectedItems.Count 显示“0”...
我找到了this,但它似乎有点复杂。是否有一个简单的解决方案可以满足我的需求?
【问题讨论】:
-
我假设 SearchResultsPresenter 是你的 GridView,如果你是 GridView,我想你会想要 Children.Count(但这会导致 a memory leak)你想要绑定到绑定路径填充网格视图以获取您的计数。可能会分享更多代码。
-
谢谢。是的,SearchResultsPresenter 是我的 GridView(实际上是来自 Telerik 的 RadGridView),其属性为 ItemsSource="{Binding SearchResults}"。我可以在 ToolTip 中使用此 Binding 而不是 Items.Count,但如何显示 SelectedItems.Count ?
标签: xaml silverlight data-binding tooltip