Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class UserControl1 : UserControl
- {
- public UserControl1()
- {
- InitializeComponent();
- }
- public int MyProperty
- {
- get { return (int)GetValue(MyPropertyProperty); }
- set { SetValue(MyPropertyProperty, value); }
- }
- public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(int), typeof(UserControl1), new PropertyMetadata(0));
- private void UserControl_Loaded(object sender, RoutedEventArgs e)
- {
- Label l = new Label
- {
- Content = MyProperty,
- Height = 40,
- Width = 30
- };
- RootGrid.Children.Add(l);
- }
- }
- <UserControl x:Class="WpfApplication1.UserControl1"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- mc:Ignorable="d"
- d:DesignHeight="300" d:DesignWidth="300" Loaded="UserControl_Loaded">
- <Grid x:Name="RootGrid">
- </Grid>
- </UserControl>
- <Window
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="clr-namespace:WpfApplication1" x:Class="WpfApplication1.MainWindow"
- Title="MainWindow" Height="350" Width="525">
- <Grid>
- <local:UserControl1 x:Name="Us" Height="34" Width="139" MyProperty="{Binding Value, ElementName=Sl}"/>
- <Slider x:Name="Sl" Height="30" VerticalAlignment="Top" Width="310" SmallChange="1"/>
- </Grid>
Add Comment
Please, Sign In to add comment