Hello everyone
I'm trying to make a UserControl with two textblock to simulate a shadow.
I have created a page form and I added three usercontrols . At designe mode everything Works fine however, after running my app any error happen but, just the third text of the usercontrol appears.
See below the code:
UserControl XAML
<UserControl
x:Name="MyUserControl">
<Grid>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Caption, ElementName=MyUserControl, Mode=TwoWay}" VerticalAlignment="Top" FontFamily="Happy Hell" FontSize="40" Margin="2,2,0,0" Foreground="Black" Opacity="0.5"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Caption, ElementName=MyUserControl, Mode=TwoWay}" VerticalAlignment="Top" FontFamily="Happy Hell" FontSize="40" Foreground="White"/>
</Grid>
</UserControl>
UserControl C#
namespace myapptest
{
public sealed partial class Label : UserControl
{
public static DependencyProperty CaptionProperty { private set; get; }
public String Caption
{
set { SetValue(CaptionProperty, value); }
get { return (String)GetValue(CaptionProperty); }
}
public Label()
{
this.InitializeComponent();
CaptionProperty = DependencyProperty.Register("Caption", typeof(string),
typeof(Label), new PropertyMetadata("", OnTextChanged));
}
static void OnTextChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
(obj as Label).OnTextChanged(args);
}
void OnTextChanged(DependencyPropertyChangedEventArgs args)
{
}
}
}
XAML MainPage
<Grid>
<local:Label x:Name="label1" HorizontalAlignment="Left" Margin="876,69,0,0" VerticalAlignment="Top" Caption="Address"/>
<local:Label x:Name="label2" HorizontalAlignment="Left" Margin="870,153,0,0" VerticalAlignment="Top" Caption="Name"/>
<local:Label x:Name="label2" HorizontalAlignment="Left" Margin="876,109,0,0" VerticalAlignment="Top" Caption="Birth date"/>
</Grid>