Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Routed Command with Bindings per-Tab
    primarykey
    data
    text
    <p>I intended to disable and enable the Buttons outside the TabControl, just like those inside the TabItem when the current tab is changed. But the CommandBindings of the TabItem do not seem to impact "up" the visual tree. What <em>is</em> the right way to do this?</p> <p>With this XAML:</p> <pre><code>&lt;Window x:Class="WpfApplication10.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication10" Title="MainWindow" Height="350" Width="525"&gt; &lt;StackPanel&gt; &lt;Button Content="MyCommand1" Command="local:MainWindow.MyCommand1" /&gt; &lt;Button Content="MyCommand2" Command="local:MainWindow.MyCommand2" /&gt; &lt;TabControl&gt; &lt;TabItem Header="tabItem1" Name="tabItem1"&gt; &lt;TabItem.CommandBindings&gt; &lt;CommandBinding Command="local:MainWindow.MyCommand1" Executed="ExecuteMyCommand" /&gt; &lt;/TabItem.CommandBindings&gt; &lt;StackPanel&gt; &lt;Button Content="MyCommand1" Command="local:MainWindow.MyCommand1" /&gt; &lt;Button Content="MyCommand2" Command="local:MainWindow.MyCommand2" /&gt; &lt;/StackPanel&gt; &lt;/TabItem&gt; &lt;TabItem Header="tabItem2" Name="tabItem2"&gt; &lt;TabItem.CommandBindings&gt; &lt;CommandBinding Command="local:MainWindow.MyCommand2" Executed="ExecuteMyCommand"/&gt; &lt;/TabItem.CommandBindings&gt; &lt;StackPanel&gt; &lt;Button Content="MyCommand1" Command="local:MainWindow.MyCommand1" /&gt; &lt;Button Content="MyCommand2" Command="local:MainWindow.MyCommand2" /&gt; &lt;/StackPanel&gt; &lt;/TabItem&gt; &lt;/TabControl&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre> <p>With this Code Behind:</p> <pre><code> public static readonly RoutedUICommand MyCommand1 = new RoutedUICommand(); public static readonly RoutedUICommand MyCommand2 = new RoutedUICommand(); public MainWindow() { InitializeComponent(); } private void ExecuteMyCommand(object sender, ExecutedRoutedEventArgs e) { MessageBox.Show("Hello"); } </code></pre>
    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