0

Hi Please help me to realize the fallowing datatemplate in code behind

<TreeView Name="OrderTree" DataContext="{Binding ordersTree}" ItemsSource="{Binding}">
    <TreeView.Resources>
        <HierarchicalDataTemplate 
              ...
        </HierarchicalDataTemplate>
        <DataTemplate DataType="{x:Type ordVM:OrderedDataCollectionVM}">
            <ListView Name="orderedListView" Margin="0,5,0,0" ItemsSource="{Binding GridData}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn DisplayMemberBinding="{Binding Number}" Width="20" />
                        <GridViewColumn Header="{x:Static lang:ViewTextResource.product_name}" DisplayMemberBinding="{Binding Product.Name}" Width="150" />
                        <GridViewColumn Header="{Binding GridHeaders.[0]}" CellTemplate="{StaticResource GridViewComboBox1}" Width="120"/>
                        <GridViewColumn Header="{Binding GridHeaders.[1]}" CellTemplate="{StaticResource GridViewComboBox2}" Width="120"/>
                    </GridView>
                </ListView.View>
            </ListView>
        </DataTemplate>
    </TreeView.Resources>
</TreeView>

I want to create a DataTemplate in code behind for my TreeView with a ListView which has a GridView which columns count depends on my data.

4

1 回答 1

0

看看这个。看起来这就是你想要的。

有趣的部分:

DataTemplate template = new DataTemplate();  

template.VisualTree = new FrameworkElementFactory(typeof(Path));  

template.VisualTree.SetBinding(Path.StrokeProperty, new Binding("Stroke"));  
template.VisualTree.SetBinding(Path.StrokeThicknessProperty, new Binding("StrokeThickness"));  
template.VisualTree.SetBinding(Path.FillProperty, new Binding("Interior"));  
template.VisualTree.SetBinding(Path.DataProperty, new Binding("Geometry"));  

只需编辑它以满足您的需要。

于 2012-08-15T08:56:12.553 回答