У меня есть текстовое поле с привязкой к ObservableCollection с тройным кортежем и вы хотите изменить привязку в зависимости от двух радиообъектов:
XAML:
<ItemsControl ItemsSource="{Binding DataInformation, Mode=OneWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox x:Name="xTextbox" Grid.Row="0"
IsReadOnly="True"
Text="{Binding Path=Item2 , Mode=OneWay}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl >
<RadioButton Grid.Row="1"
x:Name="PatoRadioButton"
Width="150"
Content="Type Pato"
Checked="PatoRadioButtonChecked" />
<RadioButton Grid.Row="2"
x:Name="FifoRadioButton"
Width="150"
Content="Type Fifo"
Checked="FifoRadioButtonChecked" />
ViewModel:
private ObservableCollection<Tuple<int, string, string>> dataInformation;
public ObservableCollection<Tuple<int, string, string>> DataInformation
{
get
{
return DataInformation;
}
set
{
dataInformation = value;
NotifyPropertyChanged("DataInformation");
}
}
ВОПРОС:
Как я могу изменить Text="{Binding Path=Item2, Mode=OneWay}"
TextBox
зависимости от проверенного RadioButton
?
Text="{Binding Path=Item2, Mode=OneWay}"
Text="{Binding Path=Item3, Mode=OneWay}"
Вы можете добавить 2 Triggers
в TextBox
вашего DataTemplate
:
<DataTemplate>
<TextBox x:Name="xTextbox" Grid.Row="0" IsReadOnly="True">
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked,
ElementName=PatoRadioButton}" Value="True">
<DataTrigger.Setters>
<Setter Property="Text" Value="{Binding Path=Item2,
Mode=OneWay" />
</DataTrigger.Setters>
</DataTrigger>
<DataTrigger Binding="{Binding IsChecked,
ElementName=FifoRadioButton}" Value="True">
<DataTrigger.Setters>
<Setter Property="Text" Value="{Binding Path=Item3,
Mode=OneWay}" />
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</DataTemplate>
Триггеры установит Binding
в TextBlock
, когда IsChecked
свойство изменяется.