Reputation: 1920
I have a Silverlight application.
I need to add a Tooltip to a textblock that will display information about an other element (a 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>
But the binding with an elementName doesn't work. Items.Count and SelectedItems.Count display "0"...
I found this but it seems a bit complicated. Is there a simple solution to do what I need ?
Upvotes: 1
Views: 1241
Reputation: 6172
<Grid>
<Grid.Resources>
<BindableObjectReference x:Key="BindableGridView"
Object="{Binding ElementName=SearchResultsPresenter}"/>
</Grid.Resources>
<RadGridView x:Name="SearchResultsPresenter"
ItemsSource="{Binding SearchResults}">
<ToolTipService.ToolTip>
<ToolTip>
<TextBlock>
<Run Text="{Binding
Path=Object.Items.Count,
Source={StaticResource BindableGridView}}"/>
<Run Text="{Binding
Path=Object.SelectedItems.Count,
Source={StaticResource BindableGridView}}"/>
</TextBlock>
<ToolTip>
<ToolTipService.ToolTip>
</RadGridView>
</Grid>
and code:
public class BindableObjectReference : DependencyObject
{
public object Object
{
get { return GetValue( ObjectProperty ); }
set { SetValue( ObjectProperty, value ); }
}
public static readonly DependencyProperty ObjectProperty =
DependencyProperty.Register( "Object", typeof( object ),
typeof( BindableObjectReference ), new PropertyMetadata( null ) );
}
Upvotes: 2