Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
770
Changing NodeLayout.ItemTemplate style programmatically
posted

Hello,

Maybe this is more of a "WPF in general " question but since I need it for my XamDataTree, it may also be related to this. 

Basically, I need to apply a particular style to my nodes, by code.

Here is my tree in xaml : 

    <UserControl.Resources>

        <Style x:Key="arretGeocode" TargetType="TextBlock">

            <Setter Property="Foreground" Value="Black"></Setter>

        </Style>

        <Style x:Key="arretNonGeocode" TargetType="TextBlock">

            <Setter Property="Foreground" Value="Red"></Setter>

        </Style>

    </UserControl.Resources>

<ig:XamDataTree Name="treeViewPoints" VerticalAlignment="Top" NodeLineVisibility="Visible" >

            <ig:XamDataTree.GlobalNodeLayouts>

                <ig:NodeLayout Key="MyLayout" TargetTypeName="GroupePointNavigateur">

                    <ig:NodeLayout.ItemTemplate>

                        <DataTemplate>

                            <StackPanel Orientation="Horizontal">

                                <TextBlock Text="{Binding Data.Groupe.Code}" Style="{StaticResource arretGeocode}"/>

                                <TextBlock Text=" - " Style="{StaticResource arretGeocode}"/>

                                <TextBlock Text="{Binding Data.Groupe.Nom}" Style="{StaticResource arretGeocode}"/>

                            </StackPanel>

                        </DataTemplate>

                    </ig:NodeLayout.ItemTemplate>

                </ig:NodeLayout>

                <ig:NodeLayout Key="MyChildLayout" TargetTypeName="VersionPoint">

                    <ig:NodeLayout.ItemTemplate>

                        <DataTemplate>

                            <StackPanel Orientation="Horizontal">

                                <TextBlock Text="{Binding Data.Point.Code}" Style="{StaticResource arretGeocode}"/>

                                <TextBlock Text=" - " Style="{StaticResource arretGeocode}"/>

                                <TextBlock Text="{Binding Data.Nom}" Style="{StaticResource arretGeocode}"/>

 

                            </StackPanel>

                        </DataTemplate>

                    </ig:NodeLayout.ItemTemplate>

                </ig:NodeLayout>

            </ig:XamDataTree.GlobalNodeLayouts>

        </ig:XamDataTree>

(Sorry for the style, I still dont understand how to put code samples in your forums...)

So, what I need to do, is to apply the "arretNonGeocode" style to the textblocks of a node, in the C# code behind. 

I dont have any problem to get the XamDataTreeNodes, it's just that I can't figure out how to change their itemtemplate when I'm in the code behind. 

Thank you in advance.

 

Parents Reply Children
No Data