Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何基于已编译资源字典中的样式创建WPF样式?_.net_Wpf_Resourcedictionary_Basedon - Fatal编程技术网

.net 如何基于已编译资源字典中的样式创建WPF样式?

.net 如何基于已编译资源字典中的样式创建WPF样式?,.net,wpf,resourcedictionary,basedon,.net,Wpf,Resourcedictionary,Basedon,我已经下载了Reuxables免费样式,并将它们作为资源字典添加到我的App.xaml中。我还添加了自己的资源字典,其中包括一个验证器模板 问题是,当我在验证器模板中添加样式目标类型以目标对象类型时,该类型的对象将丢失Reuxables库中的样式 这是我的App.xaml: <Application x:Class="App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

我已经下载了Reuxables免费样式,并将它们作为资源字典添加到我的App.xaml中。我还添加了自己的资源字典,其中包括一个验证器模板

问题是,当我在验证器模板中添加样式目标类型以目标对象类型时,该类型的对象将丢失Reuxables库中的样式

这是我的App.xaml:

<Application x:Class="App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/ReuxablesLegacy;component/edge.xaml" />
                <ResourceDictionary Source="Themes/Validator.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

这是我的验证器资源字典:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:conv="clr-namespace:WPFLibrary.Converters;assembly=WPFLibrary">
    <conv:ErrorListConverter x:Key="errorListConverter" />
    <Style x:Key="myValidatorTemplate" TargetType="Control">
    <!-- If return from converter is 'true' (where converter is handed a dictionary and property name) then set the border and tooltip accordingly -->
    <Style.Triggers>
        <DataTrigger Value="true">
        <DataTrigger.Binding>
            <MultiBinding Converter="{StaticResource errorListConverter}" ConverterParameter="EXISTS" >
            <Binding Path="ErrorList" />
            <Binding RelativeSource="{RelativeSource Self}" Path="Tag" />
            </MultiBinding>
        </DataTrigger.Binding>
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="Red" />
        <Setter Property="ToolTip" >
            <Setter.Value>
            <MultiBinding Converter="{StaticResource errorListConverter}" ConverterParameter="VALUE" >
                <Binding Path="ErrorList" />
                <Binding RelativeSource="{RelativeSource Self}" Path="Tag" />
            </MultiBinding>
            </Setter.Value>
        </Setter>
        </DataTrigger>
    </Style.Triggers>
    </Style>
    <!--List the control types that should be able to display validation errors-->
    <Style TargetType="TextBox" BasedOn="{StaticResource myValidatorTemplate}" />
    <Style TargetType="ComboBox" BasedOn="{StaticResource myValidatorTemplate}" />
    <Style TargetType="DatePicker" BasedOn="{StaticResource myValidatorTemplate}" />
    <Style TargetType="DataGrid" BasedOn="{StaticResource myValidatorTemplate}" />
    <Style TargetType="DataGridCell" BasedOn="{StaticResource myValidatorTemplate}" />
    <Style TargetType="GroupBox" BasedOn="{StaticResource myValidatorTemplate}" />
    <Style TargetType="TabItem" BasedOn="{StaticResource myValidatorTemplate}" />
</ResourceDictionary>

因为我将验证器应用于文本框、组合框、日期选择器、数据网格、分组框和选项卡项,所有这些都失去了可重用的边缘样式


我感谢任何解决办法。谢谢

我已经使用该代码成功地在多个基本样式上创建了样式
BasedOn
,但是我只尝试了命名样式,而不是隐式样式。也许它对你有用?Rachel,谢谢你的代码,它实际上很好,但它似乎不适用于隐式样式,这是我的主要问题。我几乎是在使用Reflector从Reuxables DLL中提取XAML并自己修改它们的样式,但我不认为这是100%合法的,我必须检查一下。我不确定它是否适用于隐式样式,但我希望您能够修改它,以便在需要时与它们一起工作。我不确定您是否知道,但您可以使用以下语法将样式基于隐式样式:
BasedOn=“{StaticResource{x:Type TextBox}}”
是的,我知道将样式基于隐式样式,但不知怎的,它似乎不起作用。我更改了将其声明为的验证程序模板样式上的行,得到一个错误:“在”System.Windows.Markup.StaticResourceHolder“上提供值”引发了一个异常