私の UserControl には、保存ボタンを有効にする前にすべて選択する必要がある 3 つの ComboBoxes があります。最初に null に設定されている ViewModel プロパティへのバインディングを使用して MultiDataTrigger を定義しました。したがって、コントロールが読み込まれると、ボタンは期待どおりに無効になりますが、ComboBoxes の 1 つが選択されるとすぐにボタンが有効になります。私が理解したように、MultiDataTrigger を起動するには、そのすべての条件が満たされている必要がありますか?
これが私のボタンスタイルです:
<Style x:Key="saveButton" TargetType="{x:Type Button}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=CurrentSpeech.Room, Converter={StaticResource nullToBoolConverter}}" Value="true" />
<Condition Binding="{Binding Path=CurrentSpeech.Speaker, Converter={StaticResource nullToBoolConverter}}" Value="true" />
<Condition Binding="{Binding Path=CurrentSpeech.Track, Converter={StaticResource nullToBoolConverter}}" Value="true" />
</MultiDataTrigger.Conditions>
<Setter Property="Button.IsEnabled" Value="False" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
私のコンボボックス:
<ComboBox Margin="3" Grid.Row="4" Grid.Column="1" ItemsSource="{Binding Path=Rooms, Mode=OneWay}"
SelectedItem="{Binding Path=CurrentSpeech.Room, Mode=TwoWay}" DisplayMemberPath="Name"/>
<ComboBox Margin="3" Grid.Row="5" Grid.Column="1" ItemsSource="{Binding Path=Tracks, Mode=OneWay}"
SelectedItem="{Binding Path=CurrentSpeech.Track, Mode=TwoWay}" DisplayMemberPath="Title"/>
<ComboBox Margin="3" Grid.Row="6" Grid.Column="1" ItemsSource="{Binding Path=Speakers, Mode=OneWay}"
SelectedItem="{Binding Path=CurrentSpeech.Speaker, Mode=TwoWay}" DisplayMemberPath="Name"/>
マイボタン:
<Button Style="{StaticResource saveButton}" Margin="3" Grid.Row="9" Grid.Column="1" Command="{Binding Path=CurrentSpeech.SaveCommand}" Width="150" HorizontalAlignment="Right" Content="Speichern"/>
そして私のコンバーター:
[ValueConversion(typeof(object), typeof(bool))]
public class NullToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool result = value == null ? true : false;
if (parameter != null)
return !result;
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
ありがとう、パックス