我有一个带有四个单选按钮的应用程序,可以选择我正在操作的模式。 所有4个单选按钮都绑定到同一属性。当我启动程序时,没有选中任何单选按钮。
这是单选按钮的代码:
<GroupBox Grid.Row="0" Margin="10,10,10,10" FontSize="16"
FontWeight="Bold">
<GroupBox.Header>Tipo di Rientro</GroupBox.Header>
<StackPanel>
<RadioButton Name="RdBtnExternalEntry" FontSize="12"
FontWeight="Normal" GroupName="SelectionType" IsChecked="{Binding
Path=CurrentOption, Mode=TwoWay, Converter={StaticResource
enumConverter}, ConverterParameter=ExternalEntry}">Entrata da
Esterno</RadioButton>
<RadioButton Name="RdBtnEntryAfterCheck" FontSize="12"
FontWeight="Normal" GroupName="SelectionType" IsChecked="{Binding
Path=CurrentOption, Mode=TwoWay, Converter={StaticResource
enumConverter}, ConverterParameter=EntryAfterCheck}">Rientro dopo
visione</RadioButton>
<RadioButton Name="RdBtnEntryMissingShipping" FontSize="12"
FontWeight="Normal" GroupName="SelectionType" IsChecked="{Binding
Path=CurrentOption, Mode=TwoWay, Converter={StaticResource
enumConverter}, ConverterParameter=EntryMissingShipping}">Rientro
per mancata Spedizione</RadioButton>
<RadioButton Name="RdBtnEntryAfterPicking" FontSize="12"
FontWeight="Normal" GroupName="SelectionType" IsChecked="{Binding
Path=CurrentOption, Mode=TwoWay, Converter={StaticResource
enumConverter}, ConverterParameter=EntryAfterPicking}">Rientro
dopo Picking</RadioButton>
</StackPanel>
</GroupBox>
这是属性:
public RadioOptions CurrentOption
{
get => _currentOption;
set
{
_currentOption = value;
NewLoadCommand.RaiseCanExecuteChanged();
ConfirmCommand.RaiseCanExecuteChanged();
if (value == RadioOptions.ExternalEntry)
{
_selectedStockUnitCode = PalletToDo;
SelectedLoadnumber = LoadToDo;
RaisePropertyChanged("SelectedLoadnumber");
RaisePropertyChanged("SelectedStockUnitCode");
}
else
{
SelectedLoadnumber = "0";
RaisePropertyChanged("SelectedLoadnumber");
}
RaisePropertyChanged("SelectedStockUnitCodeIsEnabled");
RaisePropertyChanged("SelectedLoadnumberIsEnabled");
}
}
这是转换器:
public class EnumMatchToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
if (value == null || parameter == null)
return false;
string checkValue = value.ToString();
string targetValue = parameter.ToString();
return checkValue.Equals(targetValue,
StringComparison.InvariantCultureIgnoreCase);
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
if (value == null || parameter == null)
return null;
bool useValue = (bool)value;
string targetValue = parameter.ToString();
if (useValue)
return Enum.Parse(targetType, targetValue);
return Binding.DoNothing;
}
}
这些是单选选项:
public enum RadioOptions { ExternalEntry, EntryAfterCheck, EntryMissingShipping, EntryAfterPicking }
我希望在程序开始时检查第一个组合框
答案 0 :(得分:0)
已解决!我当时是错误地启动了我的窗口的另一个副本,因为弹出的提示弄乱了xaml管理单选按钮的方式。我删除了一种方式,然后效果很好。