Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF CommandBinding NOT on the top level item/Window/this
    primarykey
    data
    text
    <p>All I wanted was different bindings on different tabs, so switching tabs would toggle command availability. I thought CommandBindings worked that way. </p> <p>But I've spent the last while trying to get this simple sample to work. Either I fundamentally misunderstand (and that would not be a first) or something's wrong.</p> <p>I add a CommandBinding to textBoxA but NOT to textBoxB. Moving between them should enable and disable the button which is set to the corresponding command.</p> <p>Adding the CommandBinding to the Window enables the button just fine, but that kind of kills the whole point of items-specific CommandBindings.</p> <p>Using this XAML</p> <pre><code>&lt;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"&gt; &lt;Canvas&gt; &lt;Button Canvas.Left="31" Canvas.Top="24" Content="Click Me" Name="button1" Width="100"/&gt; &lt;TextBox Canvas.Left="155" Canvas.Top="22" Height="23" Name="textBoxA" Width="120" Text="A" /&gt; &lt;TextBox Canvas.Left="298" Canvas.Top="22" Height="23" Name="textBoxB" Width="120" Text="B" /&gt; &lt;/Canvas&gt; &lt;/Window&gt; </code></pre> <p>Using this Code Behind</p> <pre><code>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) =&gt; { e.CanExecute = true; }; _Binding.Executed += (s, e) =&gt; { MessageBox.Show("Hello"); }; } </code></pre> <p>You'll see (if you try this code) that the button remains disabled, even as you move from one textbox to the other. (Even though textBoxA should enable the button because it implementes the button's CommandBinding).</p> <p>How is this supposed to work?</p> <p>Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload