I made an UserControl
that contains three toggle buttons that are each bound to different items of the same ObservableCollection
. The UserControl
is later used inside a Popup
.
For some reason, when I toggle one of them, on an other instance of the UserControl
within an other popup, it is also toggled.
The three ToggleButton
s inside the UserControl
look like this :
<DockPanel DockPanel.Dock="Top" LastChildFill="False" Margin="0, 0, 0, 8">
<TextBlock DockPanel.Dock="left" Margin="0" Text="ROTATION" Foreground="{StaticResource BaseText}" VerticalAlignment="Center"/>
<ToggleButton DockPanel.Dock="Right" Height="25" Width="25" Tag="3" IsChecked="{Binding RotationAxis[2], ElementName=RotationPanel, Converter={StaticResource BoolToString}, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="ToggleButton_Click" Content="Z"/>
<ToggleButton IsChecked="{Binding RotationAxis[1], ElementName=RotationPanel, Converter={StaticResource BoolToString}, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
<ToggleButton IsChecked="{Binding RotationAxis[0], ElementName=RotationPanel, Converter={StaticResource BoolToString}, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
</DockPanel>
They are bound to this DependencyProperty
:
public static readonly DependencyProperty RotationAxisProperty =
DependencyProperty.Register("RotationAxis", typeof(ObservableCollection<string>), typeof(RotationSelector), new PropertyMetadata(new ObservableCollection<string> { "True", "True", "True" }));
[Bindable(true)]
public ObservableCollection<string> RotationAxis
{
get { return (ObservableCollection<string>)this.GetValue(RotationAxisProperty); }
set { this.SetValue(RotationAxisProperty, value); }
}
The UserControl
is then used twice in my app :
<Popup x:Name="SpritePopupRotation">
<CMiX:RotationSelector x:Name="SpriteSelectedRotation" RotationAxis="{Binding Datacontext.SpriteRotationAxis, ElementName=Ch_Parameters, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" AxisChanged="RotationSelector_AxisChanged"/>
</Popup>
<Popup x:Name="MaskPopupRotation">
<CMiX:RotationSelector x:Name="MaskSelectedRotation" RotationAxis="{Binding Datacontext.MaskRotationAxis, ElementName=Ch_Parameters, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" AxisChanged="RotationSelector_AxisChanged"/>
</Popup>
Now, when I start my app, the three ToggleButton
s from one UserControl
look like they are bound to the other three of the other instance of the UserControl
.
Why is this happening ?