我的 WPF-(弹出)控件中有两个按钮。
首先是一个取消按钮,它只是关闭弹出窗口并始终启用。
第二个是确定按钮,只有在三个(绑定)文本框之一发生更改时才应启用该按钮。
问题是,在文本框失去焦点之前,绑定属性的值没有改变。所以该按钮直到那时才处于活动状态,因此使用鼠标不可点击。
<TextBox x:Name="tbFunction" Text="{Binding FunctionSign}" Grid.Column="1" Grid.Row="1" VerticalContentAlignment="Center" Margin="2" Padding="10 0 0 0"/>
<TextBox x:Name="tbSpecs" Text="{Binding Specs}" Grid.Column="1" Grid.Row="1" VerticalContentAlignment="Center" Margin="2" Padding="10 0 0 0"/>
<TextBox x:Name="tbSupplement" Text="{Binding Supplement}" Grid.Column="1" Grid.Row="1" VerticalContentAlignment="Center" Margin="2" Padding="10 0 0 0"/>
<!-- Footer -->
<Border Grid.Row="3" Padding="{Binding InnerContentPadding}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Style="{StaticResource OkCancelButton}" Command="{Binding CloseCommand}" Content="Abbrechen"/>
<Button Style="{StaticResource OkCancelButton}" Command="{Binding AddressChangedCommand}" Content="Ok"/>
</StackPanel>
</Border>
负责的视图模型代码:
//Private Members
private bool mPropertiesChanged = false;
private string mFunctionSign;
private string mSpecs;
private string mSupplement;
//the canExecute-method
private bool SelectionChanged(object paramer)
{
return mPropertiesChanged;
}
//Public Properties
public string FunctionSign
{
get
{
return mFunctionSign;
}
set
{
mFunctionSign = value;
mPropertiesChanged = true;
OnPropertyChanged(nameof(FunctionSign));
}
}
public string Specs
{
get
{
return mSpecs;
}
set
{
mSpecs = value;
mPropertiesChanged = true;
OnPropertyChanged(nameof(Specs));
}
}
public string Supplement
{
get
{
return mSupplement;
}
set
{
mSupplement = value;
mPropertiesChanged = true;
OnPropertyChanged(nameof(Supplement));
}
}
由于其中一个属性被更改并且相应的文本失去焦点,一切正常。
有没有办法让这个 mPropertiesChanged 为真,而 textbos 仍然有焦点?