views:

23

answers:

1

Hello! Good People

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

+2  A: 

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}}"> 
...
Andrii V
That's correct. An element can only apply a single style at one time. In order to combine styles, the easiest approach is to "inherit" a base style (your theme) from the new style which is applied to the element.
hemp
thanks man. that really saves my hassle.thanks again!!!
black sensei