- 我有幾個單選按鈕,我不想要約束他們每個人的 財產「器isChecked」代碼中的獨特屬性。
- 我想要有一個像「CurrentSelected」和 這樣的單一屬性來設置「IsChecked」。
- 另外我不想使用轉換器。
我試圖使用行爲「ChangePropertyAction」,但它看起來像 它只能以一種方式工作。這裏是我的代碼:單選按鈕與行爲結合到單一的財產
<RadioButton x:Name="UpRadioButton" Margin="5" Content="Up" > <i:Interaction.Triggers> <ei:DataTrigger Binding="{Binding IsChecked, ElementName=UpRadioButton}" Value="True"> <ei:ChangePropertyAction TargetObject="{Binding Mode=OneWay}" PropertyName="SelectedDirection" Value="{x:Static Enums:DirectionEnum.Up}" /> </ei:DataTrigger> </i:Interaction.Triggers> </RadioButton> <RadioButton x:Name="DownRadioButton" Margin="5" Content="Down" > <i:Interaction.Triggers> <ei:DataTrigger Binding="{Binding IsChecked, ElementName=DownRadioButton}" Value="True"> <ei:ChangePropertyAction TargetObject="{Binding Mode=OneWay}" PropertyName="SelectedDirection" Value="{x:Static Enums:DirectionEnum.Down}" /> </ei:DataTrigger> </i:Interaction.Triggers> </RadioButton> <RadioButton x:Name="LeftRadioButton" Margin="5" Content="Left" > <i:Interaction.Triggers> <ei:DataTrigger Binding="{Binding IsChecked, ElementName=LeftRadioButton}" Value="True"> <ei:ChangePropertyAction TargetObject="{Binding Mode=OneWay}" PropertyName="SelectedDirection" Value="{x:Static Enums:DirectionEnum.Left}" /> </ei:DataTrigger> </i:Interaction.Triggers> </RadioButton> <RadioButton x:Name="RightRadioButton" Margin="5" Content="Right" > <i:Interaction.Triggers> <ei:DataTrigger Binding="{Binding IsChecked, ElementName=RightRadioButton}" Value="True"> <ei:ChangePropertyAction TargetObject="{Binding Mode=OneWay}" PropertyName="SelectedDirection" Value="{x:Static Enums:DirectionEnum.Right}" /> </ei:DataTrigger> </i:Interaction.Triggers> </RadioButton>
我的視圖模型很簡單:MainViewModel.cs
public class MainViewModel : ViewModelBase
{
private DirectionEnum _selectedDirection;
public DirectionEnum SelectedDirection
{
get { return _selectedDirection; }
set
{
if (_selectedDirection != value)
{
_selectedDirection = value;
RaisePropertyChanged();
}
}
}
public MainViewModel()
{
SelectedDirection = DirectionEnum.Up;
}
}
,你可以從代碼,請參閱「 「RadioButton應該已經檢查... 我錯過了什麼?
它可能只有一種方法,因爲你的綁定只有一種方法......另外,轉換器有什麼問題嗎?有一個是*很好*爲此 – BradleyDotNET 2015-02-17 21:25:22
轉換器需要維護... – kaycee 2015-02-17 21:37:43
因此,一般的代碼...它的您的選擇,但說你不喜歡轉換器,因爲他們需要「維護」是一個非常糟糕的原因/在我的書中藉口。 – BradleyDotNET 2015-02-17 21:39:14