私は2つのユーザーコントロールを持っています。リストアボックスは、顧客ごとに簡単な詳細を表示するリストボックスにバインドされています。WPF - ユーザーコントロール間のリストボックスの選択項目にバインド
第2のユーザーコントロール第1のユーザーコントロールのリストボックスで選択した顧客の詳細を表示したいと思います。
最初のユーザーコントロールで選択した項目にバインドするために2番目のコントロールでバインドを設定することはできますか?
マイリストボックス:
<ListBox Name="lstCustomer" ItemsSource="{Binding Customers}" >
<ListBox.Resources>
<DataTemplate DataType="{x:Type MyApplication:Customers}">
<Label Grid.Row="0" Content="{Binding Customer.name}" FontSize="14" FontWeight="Bold" Padding="5" />
<Label Grid.Row="1" Grid.Column="0" Content="{Binding Customer.telephone}" Padding="10,5" />
</Grid>
</Grid>
</DataTemplate>
</ListBox.Resources>
</ListBox>
詳細ビュー(今のところ)のUserControl
<Grid x:Name="containingGrid" DataContext="{Binding ElementName=lstCustomers, Path=SelectedItem}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Customer.name}" FontSize="23"/>
</Grid>
おかげ グレッグ
[テキスト=「{バインディング名}」に結合するあなたのTextBlockを変更する場合は、動作するはずですが何をしています。顧客のプロパティ宣言で "名前"を "プロパティ"として識別し、それをいくつかの "ルール"に従うように変更することをお勧めします。 – Dun