I have a list of objects as the item source for the datagrid. I also have buttons with tooltips but I want the tooltips to be “localize-able”/dynamic. I don’t want to explicitly add another property on the class of the objects (would be ugly) so instead, I want to create a string in the UserControl and do something like
public string ThisTag { get { return "someString"; } }
and on the xaml
<Button ...>
<ToolTipService.ToolTip>
<Tooltip Style={StaticResource ToolTipStyle} Tag={Binding Source=thisUserControl.ThisTag} />
...
the style
<Style x:Name="ToolTipStyle" TargetType="ToolTip">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Grid>
<TextBlock Text="{TemplateBinding Tag}" Foreground="{StaticResource AnotherResource}"></TextBlock>
...
- Is that possible or is there a similar simple way to bind to a property?
- What would be the proper syntax to bind to the string?
I can’t quite make the Binding Path and ElementName style work so I settled to making a custom class like so
create an instance of the class in the App.xaml (depends where the class is declared). “local” is declared on xaml.
Then setting the tag or whatever element that needs the string in the xaml (in my case, the Tag attribute needs the binding)
I got the solution from here:
http://www.c-sharpcorner.com/uploadfile/dpatra/using-static-resource-in-silverlight-3-application/
these solutions also works for 4-5 (I think SL 5 has the “AncestorType” accr. dbaseman).