![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Why setting triggers on a ControlTemplate works but not on a style? Hi I need to understand when I should put triggers in the style and when I should put them in a ControlTemplate. I lost a couple of hours before I tried to move my logic from the Style.Triggers to a ControlTemplate.Triggers Please explain when I should use Style.Triggers and when it's useless to do so. Thanks Here is the result of my experiment. <Style x:Key="POListItemStyle2" TargetType="{x:Type ListViewItem}"> <Setter Property="Foreground" Value="Red"/> <!-- The following is commented because it doesn't work, you have to implement the logic in a template property <Style.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter Property="Background" Value="Blue"/> <Setter Property="BorderBrush" Value="Yellow" /> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true" /> <Condition Property="Selector.IsSelectionActive" Value="false" /> </MultiTrigger.Conditions> <Setter Property="Background" Value="Blue"/> <Setter Property="BorderBrush" Value="Yellow" /> </MultiTrigger> </Style.Triggers>--> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListViewItem}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> <StackPanel> <GridViewRowPresenter/> </StackPanel> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="true"> <Trigger.Setters> <Setter Property="Background" Value="Yellow"/> </Trigger.Setters> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> Any help in understanding the difference in the code above would be appreciated. Thanks Phil |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Why setting triggers on a ControlTemplate works but not on a style? Although I cannot explain this behavior... I did hit it in the past... and do remember that I used DataTriggers instead of triggers... and it worked from there... I do not see this behavior anymore.... But I have no idea why... I hope that this "temp" fix can help you... Philippe Lavoie wrote: > Hi > > I need to understand when I should put triggers in the style and when I > should put them in a ControlTemplate. I lost a couple of hours before I > tried to move my logic from the Style.Triggers to a ControlTemplate.Triggers > > Please explain when I should use Style.Triggers and when it's useless to > do so. Thanks > > Here is the result of my experiment. > > <Style x:Key="POListItemStyle2" TargetType="{x:Type ListViewItem}"> > > <Setter Property="Foreground" Value="Red"/> > <!-- The following is commented because it doesn't work, you have to > implement the logic in a template property > <Style.Triggers> > <Trigger Property="IsSelected" Value="true"> > <Setter Property="Background" Value="Blue"/> > <Setter Property="BorderBrush" Value="Yellow" /> > </Trigger> > <MultiTrigger> > <MultiTrigger.Conditions> > <Condition Property="IsSelected" Value="true" /> > <Condition Property="Selector.IsSelectionActive" > Value="false" /> > </MultiTrigger.Conditions> > <Setter Property="Background" Value="Blue"/> > <Setter Property="BorderBrush" Value="Yellow" /> > </MultiTrigger> > </Style.Triggers>--> > <Setter Property="Template"> > <Setter.Value> > <ControlTemplate TargetType="{x:Type ListViewItem}"> > <Border Background="{TemplateBinding Background}" > BorderBrush="{TemplateBinding BorderBrush}" > BorderThickness="{TemplateBinding BorderThickness}" > Padding="{TemplateBinding Padding}"> > <StackPanel> > <GridViewRowPresenter/> > </StackPanel> > </Border> > <ControlTemplate.Triggers> > <Trigger Property="IsSelected" Value="true"> > <Trigger.Setters> > <Setter Property="Background" Value="Yellow"/> > </Trigger.Setters> > </Trigger> > </ControlTemplate.Triggers> > </ControlTemplate> > </Setter.Value> > </Setter> > </Style> > > Any help in understanding the difference in the code above would be > appreciated. > > Thanks > > Phil |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Why setting triggers on a ControlTemplate works but not on astyle? I though DataTrigger didn't work with events. Anyway, I would have like to know the actual story, i.e. a bug inside WPF or there is a concept that I'm not quite grasping yet... Phil Marcus wrote: > Although I cannot explain this behavior... I did hit it in the past... > and do remember that I used DataTriggers instead of triggers... and it > worked from there... > > I do not see this behavior anymore.... But I have no idea why... > > I hope that this "temp" fix can help you... > > Philippe Lavoie wrote: > >>Hi >> >>I need to understand when I should put triggers in the style and when I >>should put them in a ControlTemplate. I lost a couple of hours before I >>tried to move my logic from the Style.Triggers to a ControlTemplate.Triggers >> >>Please explain when I should use Style.Triggers and when it's useless to >>do so. Thanks >> >>Here is the result of my experiment. >> >><Style x:Key="POListItemStyle2" TargetType="{x:Type ListViewItem}"> >> >> <Setter Property="Foreground" Value="Red"/> >> <!-- The following is commented because it doesn't work, you have to >>implement the logic in a template property >><Style.Triggers> >> <Trigger Property="IsSelected" Value="true"> >> <Setter Property="Background" Value="Blue"/> >> <Setter Property="BorderBrush" Value="Yellow" /> >> </Trigger> >> <MultiTrigger> >> <MultiTrigger.Conditions> >> <Condition Property="IsSelected" Value="true" /> >> <Condition Property="Selector.IsSelectionActive" >> Value="false" /> >> </MultiTrigger.Conditions> >> <Setter Property="Background" Value="Blue"/> >> <Setter Property="BorderBrush" Value="Yellow" /> >> </MultiTrigger> >> </Style.Triggers>--> >> <Setter Property="Template"> >> <Setter.Value> >> <ControlTemplate TargetType="{x:Type ListViewItem}"> >> <Border Background="{TemplateBinding Background}" >> BorderBrush="{TemplateBinding BorderBrush}" >> BorderThickness="{TemplateBinding BorderThickness}" >> Padding="{TemplateBinding Padding}"> >> <StackPanel> >> <GridViewRowPresenter/> >> </StackPanel> >> </Border> >> <ControlTemplate.Triggers> >> <Trigger Property="IsSelected" Value="true"> >> <Trigger.Setters> >> <Setter Property="Background" Value="Yellow"/> >> </Trigger.Setters> >> </Trigger> >> </ControlTemplate.Triggers> >> </ControlTemplate> >> </Setter.Value> >> </Setter> >> </Style> >> >>Any help in understanding the difference in the code above would be >>appreciated. >> >>Thanks >> >>Phil > > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| setting up microsoft works email | Vista mail | |||
| Font Size - XP style vs Vista style | Vista General | |||
| Font Size - XP style vs Vista style | Vista General | |||
| Font Size - XP style vs Vista style | Vista General | |||