繁体   English   中英

RadioButton未在开始时检查

[英]RadioButton Not Checked on Start

我有一个带有四个单选按钮的应用程序来选择我正在操作的模式。 所有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 }

我希望在程序开始时检查第一个组合框

解决! 我错误地推出了另一个窗口副本,因为弹出窗口会影响xaml管理单选按钮的方式。 我删除了一个istance,然后它工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM