0
私の問題は、Keyboard.LostKeyboardFocusイベントで対話トリガーが機能していないことです。しかし、私はコードの背後からそれを動作させます。 私が上げたときにKeyboard.LostKeyboardFocusで対話トリガーが発生しない
public partial class RunInformationUserControl : UserControl, INotifyPropertyChanged
{
#region Accessors
public RunInformationParameters RunInfoParams { get; set; }
public RunInformationViewModel RunViewModel { get; set; }
#endregion
#region Constructor
public RunInformationUserControl()
{
InitializeComponent();
RunViewModel = null;
}
#endregion
#region Methods
public void SetParameters(RunInformationParameters parameters)
{
this.RunInfoParams = parameters;
RunViewModel = new RunInformationViewModel(RunInfoParams);
this.DataContext = RunViewModel;
}
#endregion
#region EventHandlers
private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (RunViewModel != null)
{
OnPropertyChanged("runInfoParams");
}
}
#endregion
#region INotifyPropertyChangedEvent
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
問題があり、背後にあるコードで
#region CommandData
private ICommand _savePlateNotesCommand;
public ICommand SavePlateNotesCommand
{
get
{
return _savePlateNotesCommand ?? (_savePlateNotesCommand = new RelayCommand(OnSaveClick));
}
set
{
_savePlateNotesCommand = value;
OnPropertyChanged("SavePlateNotesCommand");
}
}
#endregion
、
<TextBox
Text="{Binding PostRunPlateNotes, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Height="113"
Width="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<i:Interaction.Triggers>
<i:EventTrigger
EventName="Keyboard.LostKeyboardFocus">
<i:InvokeCommandAction
Command="{Binding SavePlateNotesCommand}"></i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
そして、ここでのViewModelで
コードで、次のコードでテキストボックスを持っていますキーボードはコードの背後にあるフォーカスを失ってしまいます。その他のプロパティはすべて正しくバインドされています。しかし、インタラクショントリガーは機能していませんので、助けてください。
XAMLで 'Keyboard.LostKeyboardFocus'を' LostKeyboardFocus'に変更すると動作しますか? –
@SzabolcsDézsiそれはそのように動作します。 – nikhil