I have a button that looks at 2 comboboxes to make sure they matter before it is turned on. The problem is how I do this by rewriting the default style declared in my theme project.
<Button x:Name="btnOK" VerticalAlignment="Center" Content="OK" IsDefault="True" Margin="0" Click="btnOK_Click"> <Button.Style> <Style BasedOn="{StaticResource DefaultButton}"> <Style.Triggers> <DataTrigger Binding="{Binding ElementName=ddlWageTypes, Path=SelectedItem}" Value="{x:Null}"> <Setter Property="Button.IsEnabled" Value="false"/> </DataTrigger> <DataTrigger Binding="{Binding ElementName=ddlJobTitles, Path=SelectedItem}" Value="{x:Null}"> <Setter Property="Button.IsEnabled" Value="false"/> </DataTrigger> </Style.Triggers> </Style> </Button.Style> </Button>
I tried to add style BasedOn = "{StaticResouce MyDefaultButtonStyleName}" to the tag, but it explodes at runtime.
Error: The value "System.Windows.Style" cannot be assigned to the "Style" property of the "System.Windows.Controls.Button" object. It can only be based on a style with a target type, which is the base type of the "IFrameworkInputElement" Error in the object "System.Windows.Style" in the markup file "
Should it do in XAML without overwriting the default style.
EDIT: Updated sample code. I get an "OKButtonStyle" error message saying "I canโt add an item to the Resources property because the property can have only one child if it uses an explicit collection tag. Error in the" System.Windows.Style "object in the file markup "
<UserControl x:Class="UK.Budgeting.XBAP.ShiftDiff.NewFTEPremiumPaySummary" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:compModel="clr-namespace:System.ComponentModel;assembly=WindowsBase" xmlns:local="clr-namespace:UK.Budgeting.XBAP.ShiftDiff"> <UserControl.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="CellTemplates.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> <Style TargetType="{x:Type Button}" x:Key="OKButtonStyle" BasedOn="{StaticResource DefaultButton}"> <Style.Triggers> <DataTrigger Binding="{Binding ElementName=ddlWageTypes, Path=SelectedItem}" Value="{x:Null}"> <Setter Property="Button.IsEnabled" Value="false"/> </DataTrigger> <DataTrigger Binding="{Binding ElementName=ddlJobTitles, Path=SelectedItem}" Value="{x:Null}"> <Setter Property="Button.IsEnabled" Value="false"/> </DataTrigger> </Style.Triggers> </Style> </UserControl.Resources> <Grid> <Rectangle Style="{StaticResource DialogRectangle}"/> <Border Style="{StaticResource DialogBorder}"> <Grid HorizontalAlignment="Center" VerticalAlignment="Center" Background="White"> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition Width="5"/> <ColumnDefinition MinWidth="300"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition Height="2"/> <RowDefinition/> <RowDefinition Height="2"/> <RowDefinition/> <RowDefinition Height="2"/> <RowDefinition/> </Grid.RowDefinitions> <TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource LabelStyle}">Wage Type</TextBlock> <TextBlock Grid.Column="0" Grid.Row="2" Style="{StaticResource LabelStyle}">Job Title</TextBlock> <ComboBox x:Name="ddlWageTypes" VerticalAlignment="Top" Grid.Column="2" Grid.Row="0" DisplayMemberPath="DisplayName" SelectedValuePath="WageTypeCode"/> <ComboBox x:Name="ddlJobTitles" VerticalAlignment="Top" Grid.Column="2" Grid.Row="2" DisplayMemberPath="JobTitle" SelectedValuePath="JobCode"/> <StackPanel Grid.Column="2" Grid.Row="6" VerticalAlignment="Top" Orientation="Horizontal" Margin="5"> <Button x:Name="btnOK" VerticalAlignment="Center" Content="OK" IsDefault="True" Margin="0" Click="btnOK_Click" Style="{StaticResource OKButtonStyle}"/> <Button x:Name="btnCancel" VerticalAlignment="Center" Content="Cancel" IsCancel="True" Margin="10,0,0,0" Click="btnCancel_Click"/> </StackPanel> </Grid> </Border> </Grid> </UserControl>
styles wpf xaml isenabled
Nate
source share