DataTemplate で ListBox を使用しています。
<ListBox Grid.Row="1" Grid.ColumnSpan="3" Grid.RowSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ItemsSource="{Binding Order.OrderLines}" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0">Qty</TextBlock>
<TextBox Text="{Binding LineQty, Mode=TwoWay}" Grid.Column="1" />
<TextBlock Grid.Row="1" Grid.Column="0">Weight</TextBlock>
<TextBox Text="{Binding Path=LineWeight}" Grid.Row="1" Grid.Column="1" />
<TextBlock Grid.Column="0" Grid.Row="2">Pallet Weights</TextBlock>
<TextBox Text="{Binding PalletWeights}" Grid.Row="2" Grid.Column="1" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
TextBox 値は適切にバインドされています。問題は、ViewModel に "ViewMode" というプロパティがあり、TextBox の IsEnabled プロパティが App.xaml スタイルの DataTrigger にバインドされていることです。
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding ViewMode}" Value="Add">
<Setter Property="BorderBrush" Value="White"></Setter>
<Setter Property="BorderThickness" Value="2,2,0,0"></Setter>
<Setter Property="BorderBrush" Value="Black"></Setter>
<Setter Property="BorderThickness" Value="0,0,2,2"></Setter>
<Setter Property="Background" Value="LightBlue"></Setter>
<Setter Property="Foreground" Value="Black"></Setter>
<Setter Property="FontWeight" Value="Bold"></Setter>
<Setter Property="IsEnabled" Value="true"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ViewMode}" Value="Edit">
<Setter Property="BorderBrush" Value="White"></Setter>
<Setter Property="BorderThickness" Value="2,2,0,0"></Setter>
<Setter Property="BorderBrush" Value="Black"></Setter>
<Setter Property="BorderThickness" Value="0,0,2,2"></Setter>
<Setter Property="Background" Value="LightBlue"></Setter>
<Setter Property="Foreground" Value="Black"></Setter>
<Setter Property="FontWeight" Value="Bold"></Setter>
<Setter Property="IsEnabled" Value="true"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ViewMode}" Value="View">
<Setter Property="IsEnabled" Value="false"></Setter>
<Setter Property="Foreground" Value="Gray"></Setter>
</DataTrigger>
</Style.Triggers>
<Setter Property="Margin" Value="2" />
</Style>
これは、他のすべての TextBox で機能します。IsEnabled プロパティを DataTemplate 内から機能させるにはどうすればよいですか? ListBox の DataContext は ViewModel プロパティの「Order」を参照しているので、ViewModel プロパティの「ViewMode」を見ることができるはずだと思います。
ありがとう、シド。