WPF-为什么Visual studio设计图面在使用不同程序集中定义的按钮控件模板时停止数据绑定?
我在当前项目上工作了一年多,现在我正在尝试将设计时数据重新拟合到视图中。应用程序有一个基本资源字典,其中包含控件的默认样式。应用程序能够加载一个插件,该插件可以覆盖部分或所有默认样式,因此在下面的示例中,资源字典包含在外部程序集中 注意:对于提供的演示项目来说,这并不是什么大问题,但是在实际应用程序中会引起麻烦,而实际应用程序首先突出了这个问题 观点: 外部程序集中包含的ResourceDictionary: 那么设计器就不能正确更新。文本块没有内容,网格缩小到硬编码按钮内容的大小。 设计者似乎尊重资源字典中定义的样式,但ControlTemplate的存在似乎破坏了数据绑定。如果删除了ButtonStyle样式块中的ControlTemplate和关联的Setter,则设计器的行为正常。此外,更改ButtonStyle中的Padding属性也会导致设计器刷新数据绑定,并且所有内容都显示为正常,直到编译应用程序时,数据绑定中断并再次返回到极简设计图面 我不知道这是否会成为Expression Blend中的一个问题。不幸的是,我目前无法访问Blend,因为我以前安装的试用版已经过期 有人知道这里发生了什么,更重要的是,如何解决它吗 可以找到VS2012演示解决方案WPF-为什么Visual studio设计图面在使用不同程序集中定义的按钮控件模板时停止数据绑定?,wpf,visual-studio,xaml,wpf-controls,Wpf,Visual Studio,Xaml,Wpf Controls,我在当前项目上工作了一年多,现在我正在尝试将设计时数据重新拟合到视图中。应用程序有一个基本资源字典,其中包含控件的默认样式。应用程序能够加载一个插件,该插件可以覆盖部分或所有默认样式,因此在下面的示例中,资源字典包含在外部程序集中 注意:对于提供的演示项目来说,这并不是什么大问题,但是在实际应用程序中会引起麻烦,而实际应用程序首先突出了这个问题 观点: 外部程序集中包含的ResourceDictionary: 那么设计器就不能正确更新。文本块没有内容,网格缩小到硬编码按钮内容的大小。 设计者似乎
<UserControl x:Class="DesignTimeData.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DesignTimeData"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:ViewModel, IsDesignTimeCreatable=True, CreateList=False}"
d:DesignHeight="300"
d:DesignWidth="300">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ViewsModule;component/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Style="{DynamicResource TextStyle}"
Text="{Binding Row1Text}" />
<TextBlock Grid.Row="1"
Style="{DynamicResource TextStyle}"
Text="{Binding Row2Text}" />
<Button Content="Button Text"
Grid.Row="2"
Style="{StaticResource ButtonStyle}" />
</Grid>
</UserControl>
namespace DesignTimeData
{
class ViewModel
{
private string row1Text;
public string Row1Text
{
get { return row1Text; }
set { row1Text = value; }
}
private string row2Text;
public string Row2Text
{
get { return row2Text; }
set { row2Text = value; }
}
public ViewModel()
{
row1Text = "Dummy Row 1";
row2Text = "Dummy Row 2";
}
}
}
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="TextStyle"
TargetType="{x:Type TextBlock}">
<Setter Property="Background"
Value="CornflowerBlue" />
<Setter Property="FontSize"
Value="28" />
<Setter Property="TextAlignment"
Value="Center" />
<Setter Property="HorizontalAlignment"
Value="Stretch" />
<Setter Property="VerticalAlignment"
Value="Stretch" />
<Setter Property="Foreground"
Value="Beige" />
</Style>
<ControlTemplate x:Key="CustomButtonTemplate"
TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<LinearGradientBrush StartPoint="0.5,0"
EndPoint="0.5,1">
<GradientStop Offset="0"
Color="LightBlue" />
<GradientStop Offset="1"
Color="DarkBlue" />
</LinearGradientBrush>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
</ControlTemplate>
<Style x:Key="ButtonStyle"
TargetType="{x:Type Button}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0"
EndPoint="0.5,1">
<GradientStop Offset="0"
Color="DarkBlue" />
<!--<GradientStop Offset="0.5"
Color="Blue" />-->
<GradientStop Offset="1"
Color="LightBlue" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush"
Value="Red" />
<Setter Property="BorderThickness"
Value="3" />
<Setter Property="Content"
Value="{Binding Content}" />
<Setter Property="Padding"
Value="5,5,5,5" />
<Setter Property="FontSize"
Value="26" />
<Setter Property="Width"
Value="200" />
<Setter Property="Foreground"
Value="DarkBlue" />
<Setter Property="Template"
Value="{StaticResource CustomButtonTemplate}" />
</Style>
</ResourceDictionary>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ViewsModule;component/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>