C# Catel:基于另一个第三方样式创建新的DataWindowButton样式
参考: 使用Visual Studio 2013、.NET 4.5.1、Catel 4.4 我有一个带有默认关闭按钮的数据窗口。我想样式的按钮使用平面按钮样式。如果我可以直接访问DataWindowClose按钮(我认为它是在运行时创建的),我会在XAML中应用平面按钮样式,但我没有 在Catel文档中,评论说我们应该指定自己的DataWindowButtonStyle。我可以举一个例子,创建一个新的DataWindowButtonStyle,我可以基于MahApps.Metro平面按钮样式吗 如果您有任何问题或需要更多信息,请告诉我 谢谢 编辑:以下是我尝试过的:C# Catel:基于另一个第三方样式创建新的DataWindowButton样式,c#,wpf,xaml,catel,C#,Wpf,Xaml,Catel,参考: 使用Visual Studio 2013、.NET 4.5.1、Catel 4.4 我有一个带有默认关闭按钮的数据窗口。我想样式的按钮使用平面按钮样式。如果我可以直接访问DataWindowClose按钮(我认为它是在运行时创建的),我会在XAML中应用平面按钮样式,但我没有 在Catel文档中,评论说我们应该指定自己的DataWindowButtonStyle。我可以举一个例子,创建一个新的DataWindowButtonStyle,我可以基于MahApps.Metro平面按钮样式吗
<catel:DataWindow.Resources>
<!-- Compile Error: A 'DynamicResourceExtension' cannot be set on the BasedOn property of type 'Style'.
<ResourceDictionary>
<Style x:Key="DataWindowButtonStyle" BasedOn="{DynamicResource MetroFlatButton}" />
</ResourceDictionary>
-->
<!-- This compiles and runs, but doesn't work.
<ResourceDictionary>
<Style x:Key="DataWindowButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Yellow" />
</Style>
</ResourceDictionary>
-->
<!-- This compiles and runs, but doesn't work.
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Catel.MVVM;component/themes/generic.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="DataWindowButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Yellow" />
</Style>
</ResourceDictionary>
-->
<!-- Compiles and runs, but doesn't work. -->
<Style x:Key="DataWindowButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Yellow" />
</Style>
</catel:DataWindow.Resources>
您只需定义一个新的DataWindowButtonStyle资源,它应该自动应用。必须在App.xaml应用程序资源中定义自定义DataWindowButtonStyle
App.xaml:
<Application.Resources>
<Style x:Key="DataWindowButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Yellow"/>
<Setter Property="Foreground" Value="Red"/>
<Setter Property="MinHeight" Value="50"/>
</Style>
</Application.Resources>
我不知道为什么设置背景属性不起作用。但是其他属性正在工作。谢谢您的回复,但是我从您的文档中了解了DataWindowButtonStyle资源。我所希望的是一个如何做到这一点的例子。我尝试过的所有东西要么无法编译,要么无法工作。我想上传我尝试过的东西,但我没有看到上传文件的方法。请随意在Catel的官方问题跟踪器中创建一张罚单,在那里你可以上传文件。我不认为这是一个bug,因为我缺乏知识。我很确定我没有正确的XAML,因此DataWindow使用我的按钮样式,而不是它自己的内置样式。当然,如果我在原始帖子中添加的任何尝试都是正确的,请让我知道,我会重新测试。如果失败,我将向Catel tracker添加一个问题。谢谢