Guest User

Untitled

a guest
Jan 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. public partial class UserControl1 : UserControl
  2. {
  3. public UserControl1()
  4. {
  5. InitializeComponent();
  6. }
  7.  
  8. public int MyProperty
  9. {
  10. get { return (int)GetValue(MyPropertyProperty); }
  11. set { SetValue(MyPropertyProperty, value); }
  12. }
  13.  
  14. public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(int), typeof(UserControl1), new PropertyMetadata(0));
  15.  
  16. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  17. {
  18. Label l = new Label
  19. {
  20. Content = MyProperty,
  21. Height = 40,
  22. Width = 30
  23. };
  24. RootGrid.Children.Add(l);
  25. }
  26. }
  27.  
  28. <UserControl x:Class="WpfApplication1.UserControl1"
  29. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  30. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  31. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  32. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  33. mc:Ignorable="d"
  34. d:DesignHeight="300" d:DesignWidth="300" Loaded="UserControl_Loaded">
  35. <Grid x:Name="RootGrid">
  36.  
  37. </Grid>
  38. </UserControl>
  39.  
  40. <Window
  41. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  42. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  43. xmlns:local="clr-namespace:WpfApplication1" x:Class="WpfApplication1.MainWindow"
  44. Title="MainWindow" Height="350" Width="525">
  45. <Grid>
  46. <local:UserControl1 x:Name="Us" Height="34" Width="139" MyProperty="{Binding Value, ElementName=Sl}"/>
  47. <Slider x:Name="Sl" Height="30" VerticalAlignment="Top" Width="310" SmallChange="1"/>
  48. </Grid>
Add Comment
Please, Sign In to add comment