我不理解一件事。如果LicencePlate很糟糕,我的表單已經打開。在這種形式中,我有幾個按鈕,文本框和單選按鈕。這些按鈕和單選按鈕根據條件啓用和禁用。打開表格時,按鈕和單選按鈕顯示爲禁用
有一段文本框LicencePlate的代碼,它將禁用或啓用這些單選按鈕和按鈕。
// <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");
}
}
當我打開窗體。所有字段都禁用。當我點擊LicencePlate TextBox並寫一些想法時,條件激活。但是我想在表單打開時激活條件。不是在我在LicencePlate文本框中寫入一些文本之後。我還在特定的單選按鈕和按鈕上綁定了更新源觸發器。
這裏是屬性集:
public bool CanEnableButton
{
get
{
return _canEnableBtn;
}
set
{
if (_canEnableBtn != value)
{
_canEnableBtn = value;
NotifyPropertyChanged("CanEnableButton");
}
}
}
public bool CanEnableRadio
{
get
{
return _canEnableRadio;
}
set
{
if (_canEnableRadio != value)
{
_canEnableRadio = value;
NotifyPropertyChanged("CanEnableRadio");
}
}
}
public bool CanEnableAccept
{
get
{
return _canEnableAcpt;
}
set
{
if (_canEnableAcpt != value)
{
_canEnableAcpt = value;
NotifyPropertyChanged("CanEnableAccept");
}
}
}
這裏單選按鈕和按鈕的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}"/>
任何提示嗎?非常感謝。
您可以張貼在那裏此屬性設置 – GuidoG
同時又有實際禁用控制代碼的所有代碼,在你的問題,我看不出有任何代碼,啓用/禁用任何控制 – GuidoG
好的,我張貼我的代碼xaml和布爾屬性以及 –