Hi guys,
Any help on this problem would be greatly appreciated as I have been looking around all day for answers surrounding this area!
I have applied a global style to my WPF application by adding in a merged dictionary to the App.xaml. This has applied the style across the application like intended but there are a number of things that it has done that I do not fully understand.
I can give you the code that the style is applying if that will help but it is quite large so though it best not to clog this post. The style applies a background colour to each of the listbox items as well as cool hover over animations and colour changes. This style was not applied to a couple of the listboxes in my application though, code example of one below:
<StackPanel Margin="0,15,0,0" Width="auto" HorizontalAlignment="Left">
<StackPanel.Resources>
<converter:IntToBoolConverter x:Key="intToBoolConverter" />
<converter:BoolToVisibilityConverter x:Key="boolToVisibilityConverter" />
</StackPanel.Resources>
<Label Content="Required Vehicles" HorizontalAlignment="Center" FontWeight="Bold" />
<ListBox x:Name="lstVehicleRequests" ItemsSource="{Binding VehicleRequests}" Width="auto"
IsSynchronizedWithCurrentItem="True">
<ListBox.Resources>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource BaseListBoxItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=RequestStatus.RequestStatusId}" Value="7">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFFFFFB" Offset="0" />
<GradientStop Color="IndianRed" Offset="0.5" />
<GradientStop Color="#FFFFFFFB" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="4" />
</Grid.RowDefinitions>
<StackPanel Margin="0,8,0,0">
<TextBlock Margin="0,4,10,0" >
<Label Content="Coach Type" Width="120" />
<ComboBox ItemsSource="{Binding DataContext.CoachTypes,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
SelectedItem="{Binding CoachType}" DisplayMemberPath="Name" Width="100" />
</TextBlock>
<TextBlock Margin="0,8,10,0">
<Label Content="No of Passengers" Width="120" />
<TextBox
keys:ValidKeys.Numeric="True"
Validation.ErrorTemplate="{StaticResource validationTemplate}"
Style="{StaticResource textBoxInError}" Width="50">
<TextBox.Text>
<Binding Path="Passengers"
UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<val:RegularExpressionRule
ErrorDescription="Please Enter a Numeric Size"
RegularExpression="^\d*$" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</TextBlock>
<TextBlock Margin="0,8,10,0">
<Label Content="No of Drivers" Width="120" />
<TextBox
keys:ValidKeys.Numeric="True"
Validation.ErrorTemplate="{StaticResource validationTemplate}"
Style="{StaticResource textBoxInError}" Width="50">
<TextBox.Text>
<Binding Path="Drivers"
UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<val:RegularExpressionRule
ErrorDescription="Please Enter a Numeric Size"
RegularExpression="^\d*$" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</TextBlock>
<TextBlock Margin="0,8,10,0">
<Label Content="Positioning Feeder Drivers" Width="120" />
<TextBox
keys:ValidKeys.Numeric="True"
Style="{StaticResource textBoxInError}" Width="50" MaxLength="3">
<TextBox.Text>
<Binding Path="PositioningFeederDrivers"
UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<val:RegularExpressionRule
ErrorDescription="Please Enter a Numeric Size"
RegularExpression="^\d*$" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</TextBlock>
<TextBlock Margin="0,8,10,0">
<Label Content="Wheelchair Access" Width="120" />
<ComboBox Width="100" SelectedIndex="{Binding WheelchairAccess,
Converter={StaticResource intToBoolConverter}}">
<ComboBoxItem Content="Not Required" />
<ComboBoxItem Content="Required" />
</ComboBox>
</TextBlock>
<TextBlock Margin="0,8,10,8">
<Label Content="Trailer" Width="120" />
<ComboBox Width="100" SelectedIndex="{Binding Trailer,
Converter={StaticResource intToBoolConverter}}">
<ComboBoxItem Content="Not Required" />
<ComboBoxItem Content="Required" />
</ComboBox>
</TextBlock>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
I then added the BasedOn property as you can see above, why did I have to do this to get the style applied to this list box? Other listboxes and different controls picked this up automatically?
Anyway, you will see that I have a datatrigger against this listbox which should change the backround colour when the request status id = 7. Without the based on property the row successfully changes colour to red. When the style is applied it never changes colour and the orange colour from the template is always applied.
HELP?????
Much appreciated,
Mark