Сделал UserControl там зависимое свойство-коллекция. На форме разместил несколько таких контролов с разными параметрами. Но почему-то каждый из этих контролов видит это свойство не как набор всех элементов заданных внутри него, а как конкатенацию коллекций, заданных для всех контролов, размещенных на форме.
XAML :
<my1:CommonCtrlKirishi Rows="22" Floors="12">
<my1:CommonCtrlKirishi.PointsEmptyLeft>
<my1:GridPoint X="0" Y="0" />
<my1:GridPoint X="0" Y="1" />
...
<my1:GridPoint X="0" Y="10" />
</my1:CommonCtrlKirishi.PointsEmptyLeft>
</my1:CommonCtrlKirishi>
</TabItem>
<TabItem Header="Штабелер 2">
<my1:CommonCtrlKirishi StackerID="2" Rows="22" Floors="12">
<my1:CommonCtrlKirishi.PointsEmptyLeft>
<my1:GridPoint X="0" Y="0" />
<my1:GridPoint X="0" Y="1" />
...
<my1:GridPoint X="0" Y="9" />
<my1:GridPoint X="0" Y="10" />
<my1:GridPoint X="0" Y="11" />
</my1:CommonCtrlKirishi.PointsEmptyLeft>
<my1:CommonCtrlKirishi.PointsEmptyRight>
<my1:GridPoint X="0" Y="1" />
<my1:GridPoint X="0" Y="2" />
...
<my1:GridPoint X="0" Y="10" />
<my1:GridPoint X="0" Y="11" />
</my1:CommonCtrlKirishi.PointsEmptyRight>
</my1:CommonCtrlKirishi>
Код свойства контрола:
// Dependency Property
public static readonly DependencyProperty PointsEmptyLeftDP = DependencyProperty.Register("PointsEmptyLeft", typeof(ObservableCollection<GridPoint>), typeof(StackerControl), new FrameworkPropertyMetadata(new ObservableCollection<GridPoint>(),DepParamsChanged));
// .NET Property wrapper
[Description("Free points in left rack"), Category("Stacker")]
public ObservableCollection<GridPoint> PointsEmptyLeft
{
get
{
return (ObservableCollection<GridPoint>)GetValue(PointsEmptyLeftDP);
}
set
{
SetValue(PointsEmptyLeftDP, value);
}
}
// Dependency Property
public static readonly DependencyProperty PointsEmptyRightDP = DependencyProperty.Register("PointsEmptyRight", typeof(ItemsChangeObservableCollection<GridPoint>), typeof(StackerControl), new FrameworkPropertyMetadata(new ItemsChangeObservableCollection<GridPoint>(), DepParamsChanged));
// .NET Property wrapper
[Description("Free points in right rack"), Category("Stacker")]
public ItemsChangeObservableCollection<GridPoint> PointsEmptyRight
{
get
{
return (ItemsChangeObservableCollection<GridPoint>)GetValue(PointsEmptyRightDP);
}
set
{
SetValue(PointsEmptyRightDP, value);
}
}
public void SetParam(String propname, Object val, object oldval)
{
switch (propname)
{
...
case "PointsEmptyLeft":
restruct_left();
set_cell_styles();
break;
case "PointsEmptyRight":
restruct_right();
set_cell_styles();
break;
}
}
private static void DepParamsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
StackerControl ctrl = (StackerControl)d;
ctrl.SetParam(e.Property.Name, e.NewValue, e.OldValue);
}