Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 打开表单时,按钮和单选按钮显示为禁用状态_C#_Xaml_Mvvm - Fatal编程技术网

C# 打开表单时,按钮和单选按钮显示为禁用状态

C# 打开表单时,按钮和单选按钮显示为禁用状态,c#,xaml,mvvm,C#,Xaml,Mvvm,我不明白一件事。我有一张表格,如果车牌坏了就打开。在这个表单中,我有几个按钮、文本框和单选按钮。这些按钮和单选按钮根据条件启用和禁用 textbox LicensePlate有一段代码,它将禁用或启用这些单选按钮和按钮 // <summary> /// Fill Licence Plate with LicencePlateFinal from NotifiedTruck. /// </summary> public String LicenceP

我不明白一件事。我有一张表格,如果车牌坏了就打开。在这个表单中,我有几个按钮、文本框和单选按钮。这些按钮和单选按钮根据条件启用和禁用

textbox LicensePlate有一段代码,它将禁用或启用这些单选按钮和按钮

// <summary>
    /// Fill Licence Plate with LicencePlateFinal from NotifiedTruck.
    /// </summary>
    public String LicencePlate
    {
        get { return PlateInformation.LicencePlateFinal; }
        set
        {
            PlateInformation.LicencePlateFinal = value;               

            // Musí volat domeček - pokud se avizovaná a skutečná liší.
            // Call house - if avizo  != LicencePlateNotified
            if (LicencePlate != Avizo)
            {
                _canEnableBtn = false;
                NotifyPropertyChanged("CanEnableButton");
                _canEnableAcpt = true;
                NotifyPropertyChanged("CanEnableAccept");
                _canEnableRadio = true;
                NotifyPropertyChanged("CanEnableRadio");                  
            }

            // Avizovaná se rovná skutečné, ale liší se od OCRkované: povolují nakládku tlačítkem Pokračovat v nakládce která otevře detail vozidla v samostatném formuláři
            // Avizo == LicencePlateFinal , but Avizo != OCR  or LicencePlateFinal != OCR; then you can continue in loading process.
            else if (LicencePlate == Avizo || LicencePlate != PlateInformation.LicencePlateOCR || Avizo != PlateInformation.LicencePlateOCR)
            {
                _canEnableBtn = true;
                NotifyPropertyChanged("CanEnableButton");
                _canEnableAcpt = false;
                NotifyPropertyChanged("CanEnableAccept");
                _canEnableRadio = false;
                NotifyPropertyChanged("CanEnableRadio");                   
            }
            NotifyPropertyChanged("LicencePlate");
        }
    }      
这里是单选按钮和按钮的xaml:

<Button x:Name="btnContinueLoading" IsEnabled="{Binding CanEnableButton, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Command="{Binding ContinueLoadingCmd}"  Style="{StaticResource DialogButton}" Content="POKRAČOVAT V NÁKLADCE" Grid.Column="1" Height="31" Width="181" HorizontalAlignment="Right" Margin="0,11,10,0" VerticalAlignment="Top">

    </Button>

    <RadioButton x:Name="chcxReturnState" Content="VRÁTIT" GroupName="Requests" IsChecked="{Binding IsReturned, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 
                             IsEnabled="{Binding CanEnableRadio, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Grid.Column="1" HorizontalAlignment="Left" Margin="130,22,0,0" Grid.Row="1" VerticalAlignment="Top" Width="61"/>
    <RadioButton x:Name="chcxWaitState" Content="POČKAT" GroupName="Requests" IsChecked="{Binding IsWaiting, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
                             IsEnabled="{Binding CanEnableRadio, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Grid.Column="1" HorizontalAlignment="Left" Margin="10,22,0,0" Grid.Row="1" VerticalAlignment="Top"/>
    <Button x:Name="button" Content="POTVRDIT" Command="{Binding ConfirmRequestCmd, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"  IsEnabled="{Binding CanEnableAccept,UpdateSourceTrigger=PropertyChanged, Mode=OneWay}" Grid.Column="1" HorizontalAlignment="Left" Margin="10,14,0,0" Grid.Row="2"  Height="31" VerticalAlignment="Top" Width="181" Style="{StaticResource DialogButton}"/>

有什么建议吗?非常感谢。

除此之外

public bool CanEnableButton
{
    get
    {
        return _canEnableBtn;
    }

    set
    {
       _canEnableBtn = value;
       NotifyPropertyChanged("CanEnableButton");
    }
}

public bool CanEnableRadio
{
    get 
    {              

        return _canEnableRadio;
    }

    set
    {
        _canEnableRadio = value;
        NotifyPropertyChanged("CanEnableRadio");
    }
}

public bool CanEnableAccept
{
    get
    {
        return _canEnableAcpt;
    }

    set
    {
         _canEnableAcpt = value;
         NotifyPropertyChanged("CanEnableAccept");
    }        
在构造函数中,根据需要设置标志。 这是可行的

假设你的构造函数是这样的

public YourConstructor()
{
 CanEnableAccept=true;
 CanEnableRadio=true;
 CanEnableButton=true;
}

你能在设置此属性的地方发布所有代码,以及实际禁用控件的代码吗?在你的问题中,我没有看到启用/禁用任何控件的代码,我发布了xaml和bool属性的代码,我猜绑定到LicensePlate的控件在打开表单时其值发生了更改,因为bindingsource已打开。这将在控件的值仍然为空时以某种方式更改属性LicensePlate。因此,在构造函数中删除从LicensePlate?更改的属性是可以的。但我需要这个条件。此条件位于字符串LicensePlate中,在条件成功与否后,它将启用按钮和收音机。将按钮“\u canEnableAcpt”的名称更改为“CanEnableAccept”更改所有标志,如以下所示:,但没有效果:/hey你是在使用mvvm light还是caliburn microno基于c#和mvvm模式的公司平台
public YourConstructor()
{
 CanEnableAccept=true;
 CanEnableRadio=true;
 CanEnableButton=true;
}