Skip to content

Instantly share code, notes, and snippets.

@MarioBinder
Created September 18, 2012 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarioBinder/3741189 to your computer and use it in GitHub Desktop.
Save MarioBinder/3741189 to your computer and use it in GitHub Desktop.
Bindable Run
public static class BindableExtender {
public static string GetBindableText(DependencyObject obj) {
return (string)obj.GetValue(BindableTextProperty);
}
public static void SetBindableText(DependencyObject obj,
string value) {
obj.SetValue(BindableTextProperty, value);
}
public static readonly DependencyProperty BindableTextProperty =
DependencyProperty.RegisterAttached("BindableText",
typeof(string),
typeof(BindableExtender),
new UIPropertyMetadata(null,
BindableTextProperty_PropertyChanged));
private static void BindableTextProperty_PropertyChanged(
DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs e) {
if (dependencyObject is Run) {
((Run)dependencyObject).Text = (string)e.NewValue;
}
}
}
public class BindableRun : Run
{
public static readonly DependencyProperty BoundTextProperty = DependencyProperty.Register("BoundText", typeof(string), typeof(BindableRun), new PropertyMetadata(new PropertyChangedCallback(BindableRun.onBoundTextChanged)));
private static void onBoundTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((Run)d).Text = (string)e.NewValue;
}
public String BoundText
{
get { return (string)GetValue(BoundTextProperty); }
set { SetValue(BoundTextProperty, value); }
}
}
<Run local:BindableExtender.BindableText="{Binding Title}" />
<Controls:BindableRun BoundText="{l:Translate support}"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment