I have created a UserControl with a dependency property named CustomLabel of type String.
The control contains Label which should display the value of CustomLabel property.
I can do this in code using OnLabelPropertyChanged event handler:
public class MyControl : UserControl
{
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
"Label",
typeof(String),
typeof(ProjectionControl),
new FrameworkPropertyMetadata("FLAT", OnLabelPropertyChanged));
private static void OnLabelPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs eventArgs)
{
((Label)FindName("myLabel")).Content = (string)GetValue("LabelProperty");
}
}
I know there must be easier way in XAML, something like:
...
<Label Content="{Binding ...point to the Label property... }"/>
...
But I have tried many combinations (RelativeSource/Pah, Source/Path, x:Reference, just writing property name...) and nothing worked...
I am expert on WinForms and learning WPF for some thime, but these things are still alien to me.
{TemplateBinding}
. Post the full XAML of the control so I can tell you how to. – Federico Berasategui Apr 16 '13 at 1:17