Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ControlTemplate and Binding problem
Message
From
24/12/2009 02:16:37
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01440313
Message ID:
01440490
Views:
30
>Hi,
>I have the following Style defined for TreeViewItem:
<Style TargetType="TreeViewItem" x:Key="StdTreeViewItemStyle">
>       <Setter Property="Template">
>            <Setter.Value>
>                <!--  Standard TreeViewItem ControlTemplate pasted here -->
>           </Setter.Value>
>      </Setter>
>        <Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" />
>        <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
>        <Style.Triggers>
>            <Trigger Property="IsSelected" Value="True">
>                <Setter Property="FontWeight" Value="Bold" />
>                <Setter Property="Foreground" Value="Red" />
>            </Trigger>
>        </Style.Triggers>
>    </Style>
Without the Template setter the IsExpanded and IsSelected bindings work fine. With the ControlTemplate in place they no longer work (before I've made any tweaks to the ControlTemplate). FWIW the Trigger *does* work.
>
>UPDATE: FWIW, the TreeView also uses a DataTemplate. This works without the ControlTemplate but with it, although the TemplateSelector is called and returns the relevant DataTemplate, the default template is actually used.......
>
>Any ideas what goes wrong here?
>TIA,
>Viv

I assume the control template you are using actually handles "IsSelected" and "IsExpanded" in the Triggers? (I know, way too obvious, but had to ask.)

One thing I see that is different from the way I write these. I always put the template last and the setters first, you have it template first and the setters last. Does it work if you switch it around? For some reason I think the setters have to exist before the template is defined. No clue why I think that.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform