Created
September 18, 2012 04:05
-
-
Save MarioBinder/3741189 to your computer and use it in GitHub Desktop.
Bindable Run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Run local:BindableExtender.BindableText="{Binding Title}" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Controls:BindableRun BoundText="{l:Translate support}"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment