원하는 것은 다른 탭에 다른 바인딩을 사용했기 때문에 탭을 전환하면 명령 가용성이 토글됩니다. CommandBindings가 그런 식으로 일한다고 생각했습니다.WPF CommandBinding 최상위 항목에 없음/Window/this
그러나이 간단한 샘플을 얻으려고 노력하면서 마지막으로 보냈습니다. 내가 근본적으로 오해하고 (또는 처음이 아닐 수도) 또는 뭔가 잘못되었습니다.
CommandBinding을 textBoxA에 추가하지만 textBoxB에는 추가하지 않습니다. 두 명령 사이를 이동하면 해당 명령에 설정된 버튼을 활성화 및 비활성화해야합니다.
CommandBinding을 창에 추가하면 버튼이 제대로 작동하지만 항목 별 CommandBindings의 전체 지점이 삭제됩니다.
public MainWindow()
{
InitializeComponent();
button1.Command = ApplicationCommands.Open;
var _Binding = new CommandBinding(button1.Command);
textBoxA.CommandBindings.Add(_Binding);
textBoxB.CommandBindings.Clear(); // nothing bound
_Binding.CanExecute += (s, e) =>
{
e.CanExecute = true;
};
_Binding.Executed += (s, e) =>
{
MessageBox.Show("Hello");
};
}
버튼을 사용하면 하나의 텍스트 상자에서 이동하면서도, 장애인 유지 (이 코드를하려고하면) 당신은 볼 뒤에이 코드를 사용하여이 XAML
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="500">
<Canvas>
<Button Canvas.Left="31" Canvas.Top="24" Content="Click Me" Name="button1" Width="100"/>
<TextBox Canvas.Left="155" Canvas.Top="22" Height="23" Name="textBoxA" Width="120" Text="A" />
<TextBox Canvas.Left="298" Canvas.Top="22" Height="23" Name="textBoxB" Width="120" Text="B" />
</Canvas>
</Window>
를 사용
다른 하나. (비록 단추의 CommandBinding을 구현하기 때문에 textBoxA가 단추를 활성화해야 함에도 불구하고).
어떻게 작동하나요?
미리 감사드립니다.
을했다 : http://stackoverflow.com/questions/3339257/wpf-routed-command-with-bindings -per-tab –