This question has already been answered:
- Forward dependency property in UserControl 2 response
There is a counter that needs to be used in two versions:
- horizontal arrangement of elements
- vertical arrangement of elements
For this, I created the BytePropertyView.xaml myself:
<Border Style="{StaticResource MainBorder}"> <WrapPanel Orientation="Vertical"> <TextBlock Grid.Row="0" Style="{StaticResource MainName}" Text="{Binding Name}"/> <ItemsControl Grid.Row="1" ItemsSource="{Binding Properties}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> !!!Сюда нужно подписаться!!! <WrapPanel/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}"/> <CheckBox IsChecked="{Binding IsChecked}"/> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </WrapPanel> </Border> But its .cs code (this is not VM, but the code that the IDE itself generates and I added DP to it) BytePropertyView.xaml.cs:
public partial class BytePropertyView : UserControl { public BytePropertyView() { InitializeComponent(); } public Orientation ItemsOrientation { get { return (Orientation)GetValue(ItemsOrientationProperty); } set { SetValue(ItemsOrientationProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty ItemsOrientationProperty = DependencyProperty.Register("ItemsOrientation", typeof(Orientation), typeof(BytePropertyView), new PropertyMetadata(Orientation.Horizontal)); } I need to sign an Orientation in ItemsControl on the ItemsOrientation property. Or how to add a custom property for the control?
{Binding ItemsOrientation, ElementName=name}- Andrew NOP