Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7924621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:50:29+00:00 2026-06-03T17:50:29+00:00

There are two different ideas about the element which plays role of default command

  • 0

There are two different ideas about the element which plays role of default command target in the “WPF Control Development” book:

Page 258» A command target is the object on which the command is
raised. ICommandSource interface contains a CommandTarget property
that can be set to a specific object. By default, the command source
itself is considered the command target.

Page 262» By default, when the CommandTarget is not set, the element
with the keyboard focus is used.

Furthermore, at this tutorial, we can leave menu items and buttons command target undefined while menu items only (i.e. and not buttons) can detect command target truly. So what’s the default command target?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:50:32+00:00Added an answer on June 3, 2026 at 5:50 pm

    I think I just understood what this means:

    If an element is focusable, it cannot detect undefined routed command
    target automatically.

    If an element is focusable, it means that it will always have keyboard focus when it is activated in order to raise a command. Thus, if it has a CommandBinding for the Command, it will always handle it itself, and if it hasn’t it will always be disabled.

    However, you can get around this by setting FocusManager.IsFocusScope to true on the control’s container, like in this XAML:

    <Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my="clr-namespace:CommandRouting"
        Title="MainWindow" Height="350" Width="525">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Menu IsMainMenu="True">
                <MenuItem x:Name="TestMenuItem" Command="{x:Static my:MainWindow.TestCommand}"/>
            </Menu>
            <GroupBox x:Name="CommandBindingOnControlsGroupBox" Header="CommandBinding on Controls" Grid.Row="1">
                <StackPanel>
                <Button x:Name="CommandBindingOnButtonButton" Command="{x:Static my:MainWindow.TestCommand}" Content="CommandBinding on Button">
                   <Button.CommandBindings>
                        <CommandBinding Command="{x:Static my:MainWindow.TestCommand}" Executed="CommandBinding_Executed" PreviewExecuted="CommandBinding_Executed"/>
                    </Button.CommandBindings>
                </Button>
                    <TextBox x:Name="CommandBindingOnTextBoxTextBox">
                        <TextBox.CommandBindings>
                            <CommandBinding Command="{x:Static my:MainWindow.TestCommand}" Executed="CommandBinding_Executed"/>
                        </TextBox.CommandBindings>
                        <TextBox.InputBindings>
                            <!-- provide alternate keyboard shortcut -->
                            <KeyBinding Key="{x:Static Key.P}" Modifiers="{x:Static ModifierKeys.Control}" Command="{x:Static my:MainWindow.TestCommand}"/>
                        </TextBox.InputBindings>
                    </TextBox>
                    <Button x:Name="CommandTargetOnButtonButton" Command="{x:Static my:MainWindow.TestCommand}" Content="CommandTarget on Button" CommandTarget="{Binding ElementName=CommandBindingOnControlsGroupBox}">
                        <Button.CommandBindings>
                            <CommandBinding Command="{x:Static my:MainWindow.TestCommand}" Executed="CommandBinding_Executed"/>
                        </Button.CommandBindings>
                    </Button>
                </StackPanel>
            </GroupBox>
            <GroupBox x:Name="CommandBindingOnContainerGroupBox" Header="CommandBinding on Container" Grid.Row="2">
                <GroupBox.CommandBindings>
                    <CommandBinding Command="{x:Static my:MainWindow.TestCommand}" PreviewExecuted="CommandBinding_Executed"/>
                </GroupBox.CommandBindings>
                <StackPanel x:Name="CommandBindingOnInnerContainerStackPanel">
                    <StackPanel.CommandBindings>
                        <CommandBinding Command="{x:Static my:MainWindow.TestCommand}" Executed="CommandBinding_Executed"/>
                    </StackPanel.CommandBindings>
                    <Button x:Name="CommandBindingOnContainerButton" Command="{x:Static my:MainWindow.TestCommand}" Content="CommandBinding on Two Containers">
                    </Button>
                    <TextBox x:Name="CommandBindingOnContainerTextBox">
                        <TextBox.InputBindings>
                            <!-- provide alternate keyboard shortcut -->
                            <KeyBinding Key="{x:Static Key.P}" Modifiers="{x:Static ModifierKeys.Control}" Command="{x:Static my:MainWindow.TestCommand}"/>
                        </TextBox.InputBindings>
                    </TextBox>
                </StackPanel>
            </GroupBox>
            <GroupBox x:Name="OtherFocusScopeGroupBox" FocusManager.IsFocusScope="True" Header="Other FocusScope, No CommandBindings" Grid.Row="3">
                <StackPanel >
                    <Button x:Name="OtherFocusScopeButton" Command="{x:Static my:MainWindow.TestCommand}" Content="Other FocusScope">
                    </Button>
                    <TextBox x:Name="OtherFocusScopeTextBox">
                        <TextBox.CommandBindings>
                            <CommandBinding Command="{x:Static my:MainWindow.TestCommand}" Executed="CommandBinding_Executed"/>
                        </TextBox.CommandBindings>
                        <TextBox.InputBindings>
                            <!-- provide alternate keyboard shortcut -->
                            <KeyBinding Key="{x:Static Key.P}" Modifiers="{x:Static ModifierKeys.Control}" Command="{x:Static my:MainWindow.TestCommand}"/>
                        </TextBox.InputBindings>
                    </TextBox>
                </StackPanel>
            </GroupBox>
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say there are two pages with two different html elements which have the
There are two different ways to create an empty object in JavaScript: var objectA
There are two pictureboxes with two different images. If I click on one picture
In our setup there are two different websites in IIS 7 setup that point
In struts I notice there are two different ways to access variables. I am
As I see it there are two different types of logging: User-focused logs, like
Is there anyway to batch two different select queries to either SQLite or SQLCE
Is there some way to sum up two different tweet number from two different
There is a page on our server that's reachable via two different URLs. http://www.spotlight.com/6213-5613-0721
I was just wondering if there is any difference between the two different new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.