Default button on initial (exterior) page

Wizard for WPF Forum

Posted 15 years ago by Bob Fera
Version: 4.5.0485
Avatar
Hello,

I have my WindowDefaultButton set to "FinishThenNext", but on my Wizard's initial (exterior) page, the default button comes up as "Cancel". Is that expected behavior, or is there another way to get the default button to be "Next" on the initial page?

Thanks!

Bob

Comments (9)

Posted 15 years ago by Bob Fera
Avatar
Well, I'm not sure what I changed other than adding a checkbox to the initial page, but now the "next" button is correctly showing as the default button. Go figure...

Bob
Posted 15 years ago by Bob Fera
Avatar
Hello again,

Well, I'm having trouble with this scenario again. In this case I need to control the default button programmatically (see my other recent thread about adding a button to the ButtonContainer and making it the default when necessary). In my "startPage_Selected" method I have the following code:

if (wizard.ButtonContainer != null && wizard.ButtonContainer.NextButton != null)
((Button)wizard.ButtonContainer.NextButton).IsDefault = true;

But, the Next button is not showing as the default button. What appears to be happening is that the "startPage_Selected" method is being called by the wizard before the ButtonContainer exists (from debug I determined that the property is null the first time it's called, hence the conditional logic).

Soooo, given that, how can I get to the button if the "page selected" event is fired before the page is fully built?

Regards,

Bob
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bob,

Maybe try calling UpdateLayout or ApplyTemplate to see if you can get it to load that way. Otherwise, another thing you could do is use the Dispatcher to invoke a delegate containing code that does this, which would kick in after everything is loaded.

Look in our Sample Browser solution for "Dispatcher.BeginInvoke" and you can find some examples of how to do an invoke.


Actipro Software Support

Posted 15 years ago by Bob Fera
Avatar
Thanks for the quick reply.

That makes some sense to me, but I'm not sure where to attempt to implement your ideas. My first few guesses didn't make any difference. For example, after looking at your examples, I added the following to the usercontrol that contains the Wizard:

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Send,
(DispatcherOperationCallback)delegate(object arg)
{
if (wizard.ButtonContainer != null &&
wizard.ButtonContainer.NextButton != null
&& wizard.SelectedPage == startPage)
((Button)wizard.ButtonContainer.NextButton).IsDefault = true;

return null;
}, null);

}

I again checked in debug, and when this method is called, the ButtonContainer is still null. Please enlighten me if you can! :-)

Thanks,

Bob

[Modified at 04/10/2009 04:32 PM]
Posted 15 years ago by Bob Fera
Avatar
Ok, I've tried something else. I moved the code from my previous post into an event handler that's fired when the startPage itself is loaded, and now I can get to the NextButton. However, even though I'm setting IsDefault to true, it's still not coming up as the default button UNTIL I click on one of the controls on the startPage.

Any thoughts?

Bob

ps: this shouldn't be this hard, should it?
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Bob,

Sometimes in WPF the templates haven't been applied until after logical events fire, which as you can see can make things tricky. Are you just trying to do this on the first page load or every page?

If you make a simple sample project that shows the issue and email it over we can take a look. It's hard to suggest anything else without being able to debug something.


Actipro Software Support

Posted 15 years ago by Bob Fera
Avatar
I'm only having trouble with it on the first page of the wizard.

I've been working all day trying to come up with a simple reproducer, but have been unsuccessful so far, so I'm not sure what to do next.

In the real application, the Wizard is sitting in a ToolWindow of an Actipro Dockmanager, and there's a ton of other stuff going on when that window is first created (getting stuff from a server, etc.) that I could never possibly put in a sample project.

Perhaps it could be simply the result of being within the Dockmanager? A while back, when I first attempted to use a Wizard control for another piece of my app, I had a similar problem. In that case, the first page had nothing on it except a Next button. Later, I had a need to add a control to the page, and as soon as I did that, the default button started working.

(Note that I haven't yet tried to build a reproducer that has the wizard within a Dockmanager.)

Regards,

Bob
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It's really hard to say without debugging it. But since WPF is look-less, it depends on styles/templates to be applied before any UI visual controls can be retrieved. Those templates aren't always applied right away depending on how controls are set up.

Perhaps having it in a tool window is causing an additional delay in the template application but again, I really can't say without seeing a simple repro.


Actipro Software Support

Posted 15 years ago by Bob Fera
Avatar
I certainly understand the difficulty. :-)

I just tried moving some initialization stuff from my UserControl's (which hosts the Wizard) constructor into its UserControl_Loaded method, and the problem has gone away. As you've been saying, it's clearly a timing issue of some sort. I wish I had been able to give you a reproducer, but at this point I think it would take me days of work, if I could do it at all.

Thank you again for all your help and attention. On to more productive stuff... :-)

Best regards,

Bob
The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.