我的应用中有3个RadioButtons:
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Margin="91,206,0,24">
<TextBlock Text="Title Language:" VerticalAlignment="Top" FontSize="20" FontWeight="Bold" HorizontalAlignment="Left" Margin="0,0,15,0" />
<RadioButton x:Name="Rad_TitleNameRomaji" Content="Romaji" FontSize="20" Margin="0,0,10,0" Checked="TitleSettingsChanged"/>
<RadioButton x:Name="Rad_TitleNameEnglish" Content="English" FontSize="20" Margin="0,0,10,0" Checked="TitleSettingsChanged"/>
<RadioButton x:Name="Rad_TitleNameJapanese" Content="Japanese" FontSize="20" Checked="TitleSettingsChanged" />
</StackPanel>
我的ListViewItem
有一个DataTemplate:
<DataTemplate x:Key="ItemTemplate_ListViewItems" >
<Grid Width="213" Height="326">
...
<TextBlock Text="{Binding WhatShouldIPutHere}) />
...
</Grid>
</DataTemplate>
ListView
&#39; ItemsSource
是List<CustClass>
。
CustClass:
public class CustClass : INotifyPropertyChanged
{
public string RomajiTitle { get; set; }
public string EnglishTitle { get; set; }
public string JapaneseTitle { get; set; }
...
public event PropertyChangedEventHandler PropertyChanged;
}
现在我想要的是当我检查&#34;英语&#34; RadioButton
,Text
内的TextBlock
的{{1}}将绑定到DataTemplate
。对于其他两个人来说也是如此。
我该如何处理?
答案 0 :(得分:1)
三个DataTriggers
应该做的伎俩
<DataTemplate x:Key="ItemTemplate_ListViewItems" >
<Grid Width="213" Height="326">
<TextBlock >
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Rad_TitleNameRomaji,Path=IsChecked}" Value="True" >
<Setter Property="Text" Value="{Binding RomajiTitle}"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=Rad_TitleNameEnglish,Path=IsChecked}" Value="True" >
<Setter Property="Text" Value="{Binding EnglishTitle}"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=Rad_TitleNameJapanese,Path=IsChecked}" Value="True" >
<Setter Property="Text" Value="{Binding JapaneseTitle}"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
</DataTemplate>