2 つのコントロールを持つ Window があります。control1 は、実行するボタンの束を持つコントロールRoutedCommands
です。2 番目のコントロールは、TabControl
ドキュメントのリストにバインドされた です。はTabControl
ContentTemplate
ユーザー コントロール、control2 であり、ListView
. DataContext
選択したタブの control1 を control2 にバインドしたいと思いListView
ます。コードは次のとおりです。
<Window x:Class="deleteme.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:deleteme"
xmlns:sc="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:s="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<sc:ArrayList x:Key="Tabs">
<local:Document Name="doc1" />
<local:Document Name="doc2" />
<local:Document Name="doc3" />
</sc:ArrayList>
</Window.Resources>
<DockPanel>
<local:control1 DockPanel.Dock="Left" />
<TabControl DockPanel.Dock="Left" ItemsSource="{StaticResource Tabs}" SelectionChanged="TabControl_SelectionChanged">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<local:control2 />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</DockPanel>
</Window>
<UserControl x:Class="deleteme.control1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:deleteme"
x:Name="control">
<StackPanel>
<ItemsControl ItemsSource="{DynamicResource Actions}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button x:Name="actionButton" Content="{Binding Path=Text}" IsEnabled="{Binding Path=actionButton_IsEnabled}" Command="{Binding Path=Command}" CommandTarget="{Binding ElementName=control, Path=DataContext}" Click="actionButton_Click" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</UserControl>
<UserControl x:Class="deleteme.control2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<ScrollViewer>
<ListView x:Name="listView" ItemsSource="{Binding Items}" >
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollViewer>
</Grid>
</UserControl>
control2のをListView
control1にバインドする理由は 2 つありListView.SelectedItem
ます。RoutedCommand.Execute
ListView
CommandTarget
私の問題は、ListView
control2 を control1 にバインドする方法がわからないことです。実際、私はWPFを初めて使用するため、問題に間違って取り組んでいる可能性が高くなります。誰か提案があれば、私はそれを感謝します。