Given a very simple custom container control CustomDock with two attached properties, IsFooBar1 and IsFooBar2. How can I ensure that visual studio will update the generated xaml for the values of IsFooBar1 if setting IsFooBar2 updates the value of IsFooBar1 when it is being changed.
The custom control:
public class CustomDock : DockPanel
{
public static readonly DependencyProperty IsFooBarProperty1 = DependencyProperty.RegisterAttached(
"IsFooBar1",
typeof(Boolean),
typeof(CustomDock),
new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)
);
public static void SetIsFooBar1(UIElement element, Boolean value)
{
element.SetValue(IsFooBarProperty1, value);
}
public static Boolean GetIsFooBar1(UIElement element)
{
return (Boolean)element.GetValue(IsFooBarProperty1);
}
public static readonly DependencyProperty IsFooBarProperty2 = DependencyProperty.RegisterAttached(
"IsFooBar2",
typeof(Boolean),
typeof(CustomDock),
new PropertyMetadata(false)
);
public static void SetIsFooBar2(UIElement element, Boolean value)
{
element.SetValue(IsFooBarProperty2, value);
element.SetValue(IsFooBarProperty1, value);
}
public static Boolean GetIsFooBar2(UIElement element)
{
return (Boolean)element.GetValue(IsFooBarProperty2);
}
}
And its use in xaml:
<Window x:Class="TestAttachedIndirectProperties.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:TestAttachedIndirectProperties">
<Grid>
<my:CustomDock Height="100" HorizontalAlignment="Left" Margin="138,123,0,0" x:Name="customDock1" VerticalAlignment="Top" Width="200">
<Button Content="Button" Height="23" Name="button1" Width="75" my:CustomDock.IsFooBar1="True" my:CustomDock.IsFooBar2="True" />
</my:CustomDock>
</Grid>
During Visual Studio design, if IsFooBar2 is changed to false, then IsFooBar1 should also be given a false value, but it is not, niether in the properties pane or in the xaml code.