0

I am new to WPF and XAML..

I want to add an TreeView into a ListView Element with a CellTemplate..

I want to bind each ListViewItem to a Custom class called "Symbol"

This Class has an Property called "Name" and a Property called "Images".

"Name" is just a String, which should be the root Element of the TreeView..

"Images" is a List of Strings.

Each entry of this list should be an Children of this TreeView..

And please do not just leave a code snippet, i want to understand how CellTemplates work!

Thank you!

<Grid>
    <ListView x:Name="listview" HorizontalAlignment="Left" Height="326" Margin="0,33,0,0" VerticalAlignment="Top" Width="499">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Symbols" Width="200"  >
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TreeView>
                                <!--
                                    what to be done here?
                                -->
                                </TreeView>
                            </StackPanel>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
    <Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="250" Margin="504,33,0,0" VerticalAlignment="Top" Width="250">
        <Border x:Name="image_preview" HorizontalAlignment="Center" Height="250" VerticalAlignment="Center" Width="250"/>
    </Border>

</Grid>
4

1 回答 1

0

首先,您应该绑定ListViewSymbol对象集合。现在,你的每个细胞ListView都绑定到Symbol对象。如果我理解正确,每个都Symbol应该是一个TreeView带有根节点标题的显示属性和显示字符串Name的子节点集合。Images

这可以通过以下方式实现:

<TreeView >
    <TreeViewItem Header="{Binding Name}" ItemsSource="{Binding Images}" />    
</TreeView>
于 2014-05-21T14:38:05.477 回答