실행 취소 다시 실행 응용 프로그램 명령을 사용할 수 있습니다. 이것은 MVVM 호환되지 않는 버전입니다 :
당신의 XAML
<TextBox Margin="5" PreviewKeyUp="TextBox_PreviewKeyUp" AcceptsReturn="False" />
에서
private List<string> _history = new List<string>();
private int _historyIndex = -1;
private void TextBox_PreviewKeyUp(object sender, KeyEventArgs e)
{
TextBox textBox = (TextBox)sender;
if (e.Key == Key.Return)
{
_history.Add(textBox.Text);
if (_historyIndex < 0 || _historyIndex == _history.Count - 2)
{
_historyIndex = _history.Count - 1;
}
textBox.Text = String.Empty;
return;
}
if (e.Key == Key.Up)
{
if (_historyIndex > 0)
{
_historyIndex--;
textBox.Text = _history[_historyIndex];
}
return;
}
if (e.Key == Key.Down)
{
if (_historyIndex < _history.Count - 1)
{
_historyIndex++;
textBox.Text = _history[_historyIndex];
}
return;
}
}
당신의 숨김 코드에서 나는 이것이 당신이 의미하는 기능입니다 바랍니다.
무엇을 시도하셨습니까? – faby
버튼을 누르거나 Enter 키를 누르면 텍스트 상자에있는 내용이 이전 명령으로 저장되기를 원하십니까? – Hayden
[응용 프로그램 명령] (http://msdn.microsoft.com/en-us/library/system.windows.input.applicationcommands%28v=vs.110%29.aspx)을 사용하여 시도한 적이 있으며 'InputBindings' 적절한 키에 '실행 취소'와 '다시 실행'을 지정 하시겠습니까? – XAMlMAX