0

由于stackoverflow上的帖子,我构建了一个WPF应用程序并设法使验证工作。我遇到的唯一问题是它覆盖了我正在使用的主题。例如,主题使文本框看起来像一个圆角矩形,但在设置绑定后它看起来像默认文本框。这是我的代码:

<Button.Style>
            <Style TargetType="{x:Type Button}">
                <Setter Property="IsEnabled" Value="false" />

                <Style.Triggers>
                <!-- Require the controls to be valid in order to press OK -->
                <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding ElementName=txtEmail, Path=(Validation.HasError)}" Value="false" />

                        </MultiDataTrigger.Conditions>
                        <Setter Property="IsEnabled" Value="true" />
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>

后面的代码是:

//Form loaded event code
txtEmail.GetBindingExpression(TextBox.TextProperty).UpdateSource();

我试图查看主题文件,但很快就迷路了。我想我可以像使用 web css 文件一样使用该文件。现在我因此禁用了数据绑定。有什么解决方法吗?感谢您阅读本文

4

1 回答 1

2

不确定这是否是根本问题,但尝试添加BasedOn="{StaticResource {x:Type Button}}"到样式元素。

Button.Style> 
            <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> 
...
于 2010-06-02T18:49:57.830 回答