나는 WPF 된 이 프로젝트 및 난 문제가 발생하지 않을 따기 마지막으로 텍스트를 변경할 때 나는 저장 버튼을 클릭합니다.
내 구성 요소를 설정을 다음과 같다:
- 도구 모음이 보기 도구 모음 VM 있는 버튼을 저장합니다. 버 클릭하 이벤트는 바인딩을 Icommand.
- 양식 보리의 텍스트 필드,바인딩 sepreate VM.
- 도구 모음기와 형태로 보기에 별도의 파일이 있습니다.
- 내 모든 Vm 에서 상속되 BindableBase(부분의 프리즘.된 이 패키지)
버튼을 클릭에,내가 값 양식에서 VM 및 저장을 간단하게 구성되어 있습니다 및 stragight 니다. 모두가 잘 것을 제외하고,편집할 때 마지막 분야,저장 버튼을 클릭하면 트리거되지 않은 초점을 잃는 이벤트입니다. 따라서,속성을 설정 이벤트가 트리거되지 않습니다. 를 클릭하여 내가 가진 것에서 필드를 편집한 후 다음 버튼을 클릭합니다. 여기 나의 코드:
public class ViewModel: BindableBase
{
private string _someText;
public string SomeText
{
get { return _someText; }
set { SetProperty(ref _someText, value); }
}
}
에서 보기 XAML:
<TextBox Text="{Binding SomeText}"/>
도구 모음에서 XAML:
<Button Command="{Binding SaveCommand}" ToolTip="Save">
</Button>
뷰 모델에 대한 도구 모음입니다.
public class ToolbarViewModel : BindableBase
{
private ICommand _saveCommand;
public ICommand SaveCommand
{
get
{
return _saveCommand ?? (_saveCommand = new BaseCommandHandler(() => {
//Save code
}, () => true));
}
}
}
코드 BaseCommandHandler:
public class BaseCommandHandler : ICommand
{
private Action _action;
private Func<bool> _canExecute;
/// <summary>
/// Creates instance of the command handler
/// </summary>
/// <param name="action">Action to be executed by the command</param>
/// <param name="canExecute">A bolean property to containing current permissions to execute the command</param>
public BaseCommandHandler(Action action, Func<bool> canExecute)
{
_action = action;
_canExecute = canExecute;
}
/// <summary>
/// Wires CanExecuteChanged event
/// </summary>
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
/// <summary>
/// Forcess checking if execute is allowed
/// </summary>
/// <param name="parameter"></param>
/// <returns></returns>
public bool CanExecute(object parameter)
{
return _canExecute.Invoke();
}
public void Execute(object parameter)
{
_action();
}
}
가 누구나 알고 깨끗하고 있는지 확인하는 방법에 초점을 분실하거나 방법을 트리거로 설정의 이벤트는 바인딩 가능성