所以,我有不同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