Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Why setting triggers on a ControlTemplate works but not on a style?

 
 
Old 07-27-2006   #1 (permalink)
Philippe Lavoie


 
 

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 SpecsSystem Spec
Old 07-31-2006   #2 (permalink)
Marcus


 
 

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 SpecsSystem Spec
Old 08-09-2006   #3 (permalink)
Philippe Lavoie


 
 

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 SpecsSystem Spec
 

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46