WPF 된 이 방법을 선택하는 텍스트를 변경 버튼 클릭

0

질문

나는 WPF 된 이 프로젝트 및 난 문제가 발생하지 않을 따기 마지막으로 텍스트를 변경할 때 나는 저장 버튼을 클릭합니다.

내 구성 요소를 설정을 다음과 같다:

  1. 도구 모음이 보기 도구 모음 VM 있는 버튼을 저장합니다. 버 클릭하 이벤트는 바인딩을 Icommand.
  2. 양식 보리의 텍스트 필드,바인딩 sepreate VM.
  3. 도구 모음기와 형태로 보기에 별도의 파일이 있습니다.
  4. 내 모든 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();
    }
}

가 누구나 알고 깨끗하고 있는지 확인하는 방법에 초점을 분실하거나 방법을 트리거로 설정의 이벤트는 바인딩 가능성

2-way-object-databinding c# mvvm prism
2021-11-23 08:41:19
1

최고의 응답

1

를 사용해야 합 UpdateSourceTrigger=PropertyChanged

<TextBox Text="{Binding TextValue, UpdateSourceTrigger=PropertyChanged}"/>

2021-11-23 08:59:41

사실 버튼을 클릭하는 것을 의미의 손실을 초점을 위한 텍스트,그래서 그것은 가 업데이트됩니다.
Haukinger

@Haukinger hmm...
dmitriy

@Haukinger,생각하는 경우,그러나 슬프게도,아니,그것을 트리거 초점을 잃
Just another Dev

@Haukinger 경우,그것 때문에 도구 모음과 텍스트 형태가 별도 컨트롤? 는 의미가 없지만....
Just another Dev

@JustanotherDev 할 수 있는 확실히 될 수 있는 경우 원본 도구 모음에 양식이 있인 모델입니다.
Jeffery

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................