我已经下载了 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>
因为我将验证器应用于文本框、组合框、日期选择器、数据网格、组框和 tabitems,所以所有这些都失去了它们的 Reuxables Edge 风格。
我感谢任何解决方案。谢谢!