Trigger problems [modified]
-
---modified. Original problem with this is solved, but I got a new problem with the same xaml --- Ok I just started in WPF so it might be very obvious. I made a UserControl which contains also a ToggleButton, when that togglebutton is pressed I want to alter the background of the border control.
<UserControl x:Class="StoreDBViewer.MyTableControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid>
<Border x:Name="MyCtrlBorder" BorderThickness="1" BorderBrush="Gray" Background="Green"><!-- Here a bunch of controls and stuff is added --> <ToggleButton x:Name="btnToggle" Margin="5,5" Click="OnToggleColView"> Button text </ToggleButton> </Border> </Grid> **<UserControl.Triggers> <Trigger SourceName="btnToggle" Property="ToggleButton.IsChecked" Value="True"> <Setter TargetName="MyCtrlBorder" Property="Border.Background" Value="Blue" /> </Trigger> </UserControl.Triggers>**
</UserControl>
This compiles correctly, but as soon as I run the app an exception is thrown( the exception is not thrown if I comment out the Trigger part). Does anyone know what might be wrong here? Regards, Davy
modified on Monday, June 30, 2008 8:55 AM
-
---modified. Original problem with this is solved, but I got a new problem with the same xaml --- Ok I just started in WPF so it might be very obvious. I made a UserControl which contains also a ToggleButton, when that togglebutton is pressed I want to alter the background of the border control.
<UserControl x:Class="StoreDBViewer.MyTableControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid>
<Border x:Name="MyCtrlBorder" BorderThickness="1" BorderBrush="Gray" Background="Green"><!-- Here a bunch of controls and stuff is added --> <ToggleButton x:Name="btnToggle" Margin="5,5" Click="OnToggleColView"> Button text </ToggleButton> </Border> </Grid> **<UserControl.Triggers> <Trigger SourceName="btnToggle" Property="ToggleButton.IsChecked" Value="True"> <Setter TargetName="MyCtrlBorder" Property="Border.Background" Value="Blue" /> </Trigger> </UserControl.Triggers>**
</UserControl>
This compiles correctly, but as soon as I run the app an exception is thrown( the exception is not thrown if I comment out the Trigger part). Does anyone know what might be wrong here? Regards, Davy
modified on Monday, June 30, 2008 8:55 AM
What is the error message of the exception (or the message of the InnerException, or the InnerException of the InnerException, or however many levels it takes to find something useful)? In cases like this, the error messages usually have a good pointer for where to start looking.
-
What is the error message of the exception (or the message of the InnerException, or the InnerException of the InnerException, or however many levels it takes to find something useful)? In cases like this, the error messages usually have a good pointer for where to start looking.
Thanks for the reply. The message of the exception itself was pretty useless, but following the innerexceptions 3 levels up I came to this message: Triggers collection members must be of type EventTrigger. So doing some research on that I found that this kind of trigger only works in ControlTemplate,DataTemplates and Style... So I guess I have to reorder some stuff in the xaml file to fit the triggers somewhere in a style or so. Regards, Davy