C# I';我试图将验证交互添加到此样式中,但它可以';我找不到房子。这里怎么了?
我从ToggleBox控件向combobox添加了样式,一切正常 但是现在我想为验证添加额外的交互。 出于某种原因,它告诉我“在对象”“ExtendedComboBoxControl”“上找不到'Validation'属性”,这是从ComboBox继承的自定义控件 我试着直接在组合框的样式中使用触发器,但出于某种原因,我可以从那里更改边框厚度,但不能更改背景或边框笔刷C# I';我试图将验证交互添加到此样式中,但它可以';我找不到房子。这里怎么了?,c#,wpf,xaml,C#,Wpf,Xaml,我从ToggleBox控件向combobox添加了样式,一切正常 但是现在我想为验证添加额外的交互。 出于某种原因,它告诉我“在对象”“ExtendedComboBoxControl”“上找不到'Validation'属性”,这是从ComboBox继承的自定义控件 我试着直接在组合框的样式中使用触发器,但出于某种原因,我可以从那里更改边框厚度,但不能更改背景或边框笔刷 <Style x:Key="ComboBoxToggleButtonStyle" TargetType="{x:Type
<Style x:Key="ComboBoxToggleButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="IsTabStop" Value="false" />
<Setter Property="Focusable" Value="false" />
<Setter Property="ClickMode" Value="Press" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="templateRoot"
Background="{StaticResource ComboBox.Static.Background}"
BorderBrush="{StaticResource ComboBox.Static.Border}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="true">
<Border x:Name="splitBorder"
Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
Margin="1"
Padding="0"
HorizontalAlignment="Right"
BorderBrush="Transparent"
BorderThickness="2,0,0,0"
SnapsToDevicePixels="true">
<Path x:Name="arrow"
Margin="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="F1 M 0,0 L 5,5 L 10,0 L 0,0"
Fill="{StaticResource Grey500Brush}" />
</Border>
</Border>
<ControlTemplate.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" />
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false" />
<Condition Binding="{Binding Validation.HasError, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false" />
</MultiDataTrigger.Conditions>
<Setter TargetName="templateRoot" Property="Background" Value="{StaticResource ComboBox.MouseOver.Background}" />
<Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource ComboBox.MouseOver.Border}" />
<Setter TargetName="templateRoot" Property="BorderThickness" Value="{StaticResource Border.Thickness.Thick}" />
<Setter TargetName="splitBorder" Property="Margin" Value="0" />
</MultiDataTrigger>
</ControlTemplate.Triggers>
</Setter.Value>
</Setter>
这并不是我想要实现的最后一个交互,但我希望在出现验证错误时,当我将鼠标悬停在组合框背景和边框笔刷上时,它们会变成绿色
相反,它告诉我它甚至找不到我控件上的属性。正如Ed Plunkett指出的那样,我所需要做的就是更改
到
您是设计组合框还是切换按钮的样式?它找不到什么属性?我使用了一个带有切换按钮的ControlTemplate向我的ComboBox添加样式,就像这个线程中建议的那样。它无法在我的ComboBoxIm上找到属性验证,它设置了一个ToggleButton的样式,ComboBox是它的祖先。该结构对于组合框的其他属性(如iEdit)工作良好,但在我的组合框中找不到属性验证。它在ComboBox中正确查找属性。ComboBox和ToggleButton都没有验证属性<代码>验证是拥有某些附加属性的类的名称。谢谢!这成功了!