0

I would like to sort the second level of my TreeView. The sorting depends on two different conditions depending on the FieldType and the Order properties. In my case it is possible that the order increases or decreases by the user. The user uses arrow up and down buttons. How can I keep the list sortet if an item is added or removed and the user changes the Order property?

My current TreeView:

<TreeView Grid.Row="0" x:Name="tvImages" ItemsSource="{Binding SelectedTemplate.Images}">
        <TreeView.Resources>
            <HierarchicalDataTemplate DataType="{x:Type entities:TemplateImageDTO}" ItemsSource="{Binding FieldSections}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Order, StringFormat=Image {0}}" Margin="0,3,0,0"/>
                </StackPanel>
            </HierarchicalDataTemplate>
            <HierarchicalDataTemplate DataType="{x:Type entities:FieldSectionDTO}">
                <DockPanel LastChildFill="False" HorizontalAlignment="Stretch" Width="Auto">
                    <StackPanel DockPanel.Dock="Left" Orientation="Horizontal">
                        <TextBlock Text="{Binding FieldType, Converter={StaticResource enumConverter}}" Margin="0,3,0,0" />
                        <TextBlock Text=" - Field " Margin="0,3,0,0" />
                        <TextBlock Text="{Binding Order, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,3,0,0" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" DockPanel.Dock="Right" Margin="0,0,10,0">
                        <Button Width="24" Height="24" Style="{DynamicResource MahApps.Metro.Styles.MetroCircleButtonStyle}">
                            <iconPacks:PackIconFontAwesome Kind="AngleUpSolid" Foreground="{DynamicResource AccentColorBrush}" />
                        </Button>
                        <Button Width="24" Height="24" Margin="10,0,0,0" Style="{DynamicResource MahApps.Metro.Styles.MetroCircleButtonStyle}">
                            <iconPacks:PackIconFontAwesome Kind="AngleDownSolid" Foreground="{DynamicResource AccentColorBrush}" />
                        </Button>
                    </StackPanel>
                </DockPanel>
            </HierarchicalDataTemplate>
        </TreeView.Resources>
    </TreeView>
Lyror
  • 924
  • 3
  • 10
  • 19

1 Answers1

0

I found my Solution here: https://stackoverflow.com/a/19363888/6751312

After the user clicked the arrow up and down button, I increase and decrease the order property and resort the list.

Lyror
  • 924
  • 3
  • 10
  • 19