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

  • SEARCH
  • Home
  • 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 7800755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:44:24+00:00 2026-06-02T00:44:24+00:00

Here is the setup (extraneous layout code removed): Window.xaml <Button Name=btn_Next Command=NextPage>Next</Button> <ContentControl Name=contentControl1

  • 0

Here is the setup (extraneous layout code removed):

Window.xaml

<Button Name="btn_Next" Command="NextPage">Next</Button>
<ContentControl Name="contentControl1" >
        <Binding ElementName="MainWindow" Path="CurrentPage"/>
</ContentControl>

Window.xaml.cs Constructor

  var nextCommand = new CommandBinding(NavigationCommands.NextPage);
  nextCommand.CanExecute += nextCommand_CanExecute;
  nextCommand.Executed += nextCommand_Executed;
  CommandBindings.Add(nextCommand);

This works great in the base example, where nextCommand_CanExecute checks if the CurrentPage is the last page. However, that logic is currently just checking an array and only works for linear navigation. However, the navigation is going to be tree-like and this will not work, where the items in the contentControl1 will sometimes branch in different directions. So, I would like to have the user control that is the CurrentPage have the opportunity to override the CanExecute. My problem is that I cannot figure out how to get the UserControl to start the CanExecute. I have tried to use a number of CommandTarget settings to no avail…my child control never has it’s CanExecute method triggered. I have even tried to use the e.ContinueRouting = true in the parent window’s CanExecute. Here is the User Control code in case that helps.

User Control Constrtuctor:

  var nextCommand = new CommandBinding(NavigationCommands.NextPage);
  nextCommand.CanExecute += nextCommand_CanExecute;
  CommandBindings.Add(nextCommand);

User Control CanExecute method:

private void nextCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
  e.CanExecute = false;
  e.Handled = true;
}
  • 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-02T00:44:25+00:00Added an answer on June 2, 2026 at 12:44 am

    Routed command events tunnel from the root of the visual tree down to the control that initiated them, and then bubble back up. Josh Smith’s article on routed commands has a good write-up of how it works (see the “Routed” section in particular) http://joshsmithonwpf.wordpress.com/2008/03/18/understanding-routed-commands/.

    The issue here is that your user control (inside of the content control), is not an “ancestor” of the button which issues the command, so the routed event never reaches it (even in passing). Given the way your visual tree is structured, I don’t think routed commands are going to be enough for you.

    The first solution that comes to mind is rigging up your own mechanism for delegating CanExecute/Executed logic to your user controls. Maybe you could define a base class or interface that is implemented by all such controls which defines the various command CanExecute/Executed methods that are needed. Then you can just have a top-level implementation which casts the currently loaded control off as your interface/base class type and call the appropriate method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, here is setup. Note the code below is SIMPLIFIED version. PHP 5.2 ENGINE:
Here is my setup. <input type=checkbox name=item1 value=100 class=100 /> <input type=checkbox name=item2 value=200
So I have a simple setup here where I make a button, place a
I need to set up an amazon server. I always here setup ubuntu on
We have a setup here that is less than ideal, We have our webserver
Here is my setup. In my application delegate, I have a property called currentFoo.
Here's the setup I have in a vs2008 solution: Data layer in a project
Here's the setup. I have web site which is essentially a simple CMS. Here
Here's the setup : http://jsfiddle.net/AndyMP/rVrjY/ What I'd like to achieve is a shadow on
So here's my setup: User spins PickerWheel, chooses which section of the app to

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.