I've created a style for a new WPF Window class and have some dependency properties on there. The one to note is
ShowHelpButton
This is supposed to toggle the visibility of the Help button on the window. The code works fine in runtime, but I cannot get it to update the UI in the design view.
Here's the class:
public class MainWindowFrame : Window
{
#region DependencyProperties
public static readonly DependencyProperty ShowHelpButtonProperty = DependencyProperty.Register(
"ShowHelpButton", typeof (bool), typeof (MainWindowFrame), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
public bool ShowHelpButton
{
get { return (bool) GetValue(ShowHelpButtonProperty); }
set { SetValue(ShowHelpButtonProperty, value); }
}
#endregion
static MainWindowFrame()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MainWindowFrame),
new FrameworkPropertyMetadata(typeof(MainWindowFrame)));
}
Here's the Style:
<Style x:Key="MainWindowStyle" TargetType="{x:Type abstractClasses:MainWindowFrame}">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="AllowsTransparency" Value="True" />
<Setter Property="Background" Value="{StaticResource LightBlueBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource BlueBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="1" />
<Setter Property="ResizeMode" Value="NoResize" />
<Setter Property="WindowStyle" Value="None" />
<Setter Property="Title" Value="New Window" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type abstractClasses:MainWindowFrame}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid x:Name="ContainerGrid" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.Triggers>
<EventTrigger RoutedEvent="Grid.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Opacity"
From="0"
To="1"
Duration="00:00:01" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
<Grid Background="Transparent" MouseDown="Window_MouseDownDrag">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<TextBlock
Margin="10,3,0,3"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Style="{StaticResource CustomTitleBarTextBlackB}"
Text="{TemplateBinding Title}" />
</Grid>
<Button
Grid.Column="1"
Width="20"
Height="20"
Margin="0,0,5,0"
HorizontalAlignment="Right"
AutomationProperties.AutomationId="Help"
Style="{StaticResource HelpButtonStyle}"
Visibility="{TemplateBinding Property=ShowHelpButton,
Converter={StaticResource BoolToVisConverter}}" />
</Grid>
<AdornerDecorator Grid.Row="1">
<ContentPresenter x:Name="WindowContent" />
</AdornerDecorator>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
And finally, here's how I'm using it:
<abstractClasses:MainWindowFrame
x:Class="Utils.UI.NewFeaturesDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:abstractClasses="clr-namespace:Utils.AbstractClasses"
xmlns:ui="clr-namespace:Utils.UI"
xmlns:utilResx="clr-namespace:Utils.Resources"
Width="775"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
ShowHelpButton="False"
SizeToContent="Height"
Style="{DynamicResource ResourceKey=MainWindowStyle}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Utils;component/WPFStyles/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
</abstractClasses:MainWindowFrame>
I've seemingly tried everything. I've added all the FrameworkPropertyMetadataOptions by doing this:
FrameworkPropertyMetadataOptions.AffectsArrange |
FrameworkPropertyMetadataOptions.AffectsMeasure |
FrameworkPropertyMetadataOptions.AffectsRender |
FrameworkPropertyMetadataOptions.AffectsParentMeasure |
FrameworkPropertyMetadataOptions.AffectsParentArrange
I've also added a callback to no avail. I've even tried restarting Visual Studio 2015. I'm starting to think it's just a VS bug, but I'm hoping someone has some idea of what's going on. Thanks for any help!