所以,我有不同datatemplates
一个listview
这里看到的物体:使用多个树视图具有相同(但克隆)的ItemsSource
<ListView Panel.ZIndex="0" x:Name="FilterList" Margin="10,0" Grid.Row="2"
Grid.ColumnSpan="3" Background="White" ItemTemplateSelector="{StaticResource
ReportFilterTemplateSelector}" ItemsSource="{Binding reportParameters,
Mode=TwoWay}" ScrollViewer.CanContentScroll="False">
我的一个样本datatemplates
的可以看到下面。一切都显得很棒。我的问题是,对于这个(和其他)datatemplates
,我可以有多个同一个实例。在这种特定情况下,treeview
itemssource
势必DataContext.OfficeListText
填充的所有元素。
<DataTemplate x:Key="office">
<Grid MinHeight="35" MaxHeight="250">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding rpName}" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" />
<Expander HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1"
Header="{Binding Path=DataContext.OfficeListText, RelativeSource=
{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
VerticalAlignment="Top" ExpandDirection="Down">
<TreeView Tag="{Binding rpParameter}" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" ItemsSource="{Binding
Path=DataContext.OfficeList, RelativeSource={RelativeSource
FindAncestor, AncestorType={x:Type UserControl}}, Mode=TwoWay}"
ItemTemplate="{StaticResource CheckBoxItemTemplate}"
ItemContainerStyle="{StaticResource TreeViewItemStyle}"/>
</Expander>
</Grid>
</DataTemplate>
的主要问题,这是一个,例如,如果我选择一个办公室说,第一treeview
,第二treeview
显示了相同的。基本上我希望他们最初有相同的itemssource,但有不同的实例。由于它们是动态生成的,所以我陷入困境。任何帮助,将不胜感激。
我不确定其他代码是否有必要,因为我相信大部分代码都是不合适的,这取决于我需要做什么来完成这项工作,但如果您想要更多,我会很乐意提供。谢谢!
你能否详细说明在“如果我选择一个办公室在说第一个树视图,第二个树视图显示相同”? – foosburger
嗯,数据模板用于绑定数据...如果你想要不同的数据源,你应该绑定到不同的实例...我相信你应该能够在控件的资源中创建一个实例并绑定到这个实例上我并没有真正了解你的问题的全貌,所以你可能想改进它... – UIlrvnd
@foosburger说两个“办公室”数据模型被显示,一个会发生什么影响另一个。我假设这是因为树视图本身绑定到相同的'DataContext.OfficeList'实例。 – jmgardn2