Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. <Window x:Class="ChainedBindingUserControl.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="MainWindow"
  5. Height="350" Width="525"
  6. xmlns:Local="clr-namespace:ChainedBindingUserControl"
  7. >
  8. <StackPanel>
  9. <TextBlock Text="{Binding Data}"
  10. Width="150"
  11. />
  12. <ComboBox ItemsSource="{Binding Origin}"
  13. Width="150"
  14. />
  15. <Label Content="--------------------------------------------------"
  16. Width="200"
  17. />
  18. <Local:UserControl1 Liste="{Binding Origin}"
  19. Noun="{Binding Data}"
  20. Height="50" Width="150"
  21. />
  22. </StackPanel>
  23. </Window>
  24.  
  25. namespace ChainedBindingUserControl
  26. {
  27. public partial class MainWindow : Window
  28. {
  29. public ObservableCollection<String> Origin
  30. {
  31. get { return (ObservableCollection<String>)GetValue(OriginProperty); }
  32. set { SetValue(OriginProperty, value); }
  33. }
  34. public static readonly DependencyProperty OriginProperty =
  35. DependencyProperty.Register("Origin", typeof(ObservableCollection<String>), typeof(MainWindow),
  36. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  37.  
  38. public String Data
  39. {
  40. get { return (String)GetValue(DataProperty); }
  41. set { SetValue(DataProperty, value); }
  42. }
  43. public static readonly DependencyProperty DataProperty =
  44. DependencyProperty.Register("Data", typeof(String), typeof(UserControl1),
  45. new FrameworkPropertyMetadata("Blablabla", FrameworkPropertyMetadataOptions.AffectsRender));
  46.  
  47.  
  48.  
  49. public MainWindow()
  50. {
  51. InitializeComponent();
  52. this.DataContext = this;
  53.  
  54. ObservableCollection<String> zog = new ObservableCollection<String>();
  55. zog.Add("A");
  56. zog.Add("B");
  57. zog.Add("C");
  58.  
  59. Origin = zog;
  60. }
  61. }
  62. }
  63.  
  64. <UserControl x:Class="ChainedBindingUserControl.UserControl1"
  65. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  66. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  67. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  68. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  69. mc:Ignorable="d"
  70. Name="root"
  71. d:DesignHeight="300" d:DesignWidth="300">
  72. <StackPanel>
  73. <TextBlock Text="{Binding Noun}"
  74. />
  75. <ComboBox ItemsSource="{Binding Liste}"
  76. />
  77. </StackPanel>
  78. </UserControl>
  79.  
  80. namespace ChainedBindingUserControl
  81. {
  82. public partial class UserControl1 : UserControl
  83. {
  84. public ObservableCollection<String> Liste
  85. {
  86. get { return (ObservableCollection<String>)GetValue(ListeProperty); }
  87. set { SetValue(ListeProperty, value); }
  88. }
  89. public static readonly DependencyProperty ListeProperty =
  90. DependencyProperty.Register("Liste", typeof(ObservableCollection<String>), typeof(UserControl1),
  91. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  92.  
  93. public String Noun
  94. {
  95. get { return (String)GetValue(NounProperty); }
  96. set { SetValue(NounProperty, value); }
  97. }
  98. public static readonly DependencyProperty NounProperty =
  99. DependencyProperty.Register("Noun", typeof(String), typeof(UserControl1),
  100. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  101.  
  102.  
  103. public UserControl1()
  104. {
  105. InitializeComponent();
  106. this.DataContext = this;
  107. }
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement