I've create user control like this:
public partial class View { public View() { InitializeComponent(); } public static DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(TeaserView) ); public string Name { get { return (string)GetValue(NameProperty); } set { SetValue(NameProperty, value); } } } XAML:
<UserControl x:Class="Controls.View" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="200" Width="164"> <Grid VerticalAlignment="Stretch" x:Name="Preview"> <Label Height="28" Content="{Binding ElementName=Preview, Path=Name}" Background="LightYellow" x:Name="name" VerticalAlignment="Top" ></Label> </Grid> </UserControl> and use it in Window1 simply in XAML:
<controls:View Height="200" Name="View1" Width="164" /> and I try set the Content in C# (Name property in this sample) but it does'n work, label's content is still empty. (All refereces, etc. are good) What's wrong?