开发者

UI and variable accesibility confusion

开发者 https://www.devze.com 2022-12-19 05:45 出处:网络
I am building my own implementation of a wizard style interface and struggling to get it working correctly, along with every other style of wizard interface I expect to encounter the same problem. See

I am building my own implementation of a wizard style interface and struggling to get it working correctly, along with every other style of wizard interface I expect to encounter the same problem. See image:

Basically I am using a grid and have my navigation elements below that. The grid will switch the screens, like so:

private void btnNext_Click(object sender, RoutedEventArgs e)
{
    Wizard.Progress++;
    SwitchUserC开发者_如何学JAVAontrol();
}

private void SwitchUserControl()
{
    switch (Wizard.Progress)
    {
        case 0:
            contentGrid.Children.RemoveRange(0, contentGrid.Children.Count);
            contentGrid.Children.Add(screen0);
            break;
        case 1:
            contentGrid.Children.RemoveRange(0, contentGrid.Children.Count);
            contentGrid.Children.Add(screen1);
            break;
        case 2:
            contentGrid.Children.RemoveRange(0, contentGrid.Children.Count);
            contentGrid.Children.Add(screen2);
            break;
        case 3:
            contentGrid.Children.RemoveRange(0, contentGrid.Children.Count);
            contentGrid.Children.Add(screen3);
            break;
    }
}

This is where I get to the problem:

That works fine to switch among the controls. The problem is, say for example on of the screens says enter a date. And I have some data validation code to run on that text field. If validation fails the textbox border goes red and a message appears. But now I don't know where this code can go. I used to have it on the button on the usercontrol screenX, but now my navigation buttons are below, and then if I want to put it on the code under those nav buttons, I can't access the textfield!

I also see this problem occuring in most implementations of wizard style interface. Most examples I see use check boxes or radio buttons so there is no error in data input. But that is not very helpful to this example.

So what are my options to achieve what I want here???


The answer to your question might be to start over with a more canonical approach. WPF supports a nice Navigation API that you can use for building wizards. Here is a sample of it at work.

With respect to validation, in the Navigation API you can use a Page class in the stead of your controls (from your example). Your Page class can have a property indicating whether it is valid or invalid and you can keep the logic of field by field input validation specific to the page.

0

精彩评论

暂无评论...
验证码 换一张
取 消