我正在尝试向此样式添加验证交互,但找不到该属性。这里有什么问题吗?

我从 ToggleBox 控件向我的组合框添加样式,一切正常。


但是现在我想为何时Validation.HasError为真添加额外的交互。出于某种原因,它告诉我“在‘对象’‘ExtendedComboBoxControl’上找不到‘验证’属性”,这是我从 ComboBox 继承的自定义控件。


我尝试直接在组合框的样式中使用触发器,但出于某种原因,我可以从那里更改边框厚度,但不能更改背景或边框画笔。


<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>

这不是我想要实现的最终交互,但我希望当我将鼠标悬停在组合框背景和边框刷上时出现验证错误时,这会使组合框背景和边框刷变为绿色。


相反,它告诉我它甚至无法在我的控制下找到该属性。


守候你守候我
浏览 84回答 1
1回答

达令说

正如 Ed Plunkett 指出的那样,我需要做的就是改变<Condition Binding="{Binding Validation.HasError, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false" />到<Condition Binding="{Binding (Validation.HasError), RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false" />
打开App,查看更多内容
随时随地看视频慕课网APP