开发者

WPF data validation is overriding theme on the interface

开发者 https://www.devze.com 2023-01-01 19:02 出处:网络
I built a WPF application and manage to get the validation working thanks to posts on stackoverflow.The only probblem i\'m having is that it\'s overriding the theme i\'m using.

I built a WPF application and manage to get the validation working thanks to posts on stackoverflow.The only probblem i'm having is that it's overriding the theme i'm using. example the theme makes the textboxes look lik开发者_JAVA技巧e a round rectangle but after setting the binding it look like the default textboxes. here is my code :

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

code behind is:

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

I've tried to look into the theme file but i was quickly lost.i thought i could use that file like a web css file.Now i've disabled the data binding because of that.Is there any work around for this? thanks for reading this


Not sure if that's the root problem, but try adding BasedOn="{StaticResource {x:Type Button}}" to style element.

Button.Style> 
            <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> 
...
0

精彩评论

暂无评论...
验证码 换一张
取 消