UI 和变量可访问性混淆
我正在构建自己的向导样式界面的实现,并努力使其正常工作,以及我预计会遇到相同问题的所有其他样式的向导界面。看图片:
基本上我使用的是网格,并且我的导航元素位于其下方。网格将切换屏幕,如下所示:
private void btnNext_Click(object sender, RoutedEventArgs e)
{
Wizard.Progress++;
SwitchUserControl();
}
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;
}
}
这就是我遇到问题的地方:
在控件之间切换效果很好。问题是,例如,屏幕上显示输入日期。我有一些数据验证代码可以在该文本字段上运行。如果验证失败,文本框边框将变为红色并显示一条消息。但现在我不知道这段代码可以去哪里。我曾经将它放在用户控制 screenX 上的按钮上,但现在我的导航按钮位于下面,然后如果我想将它放在这些导航按钮下的代码上,我将无法访问文本字段!
我还发现这个问题出现在大多数向导风格界面的实现中。我看到的大多数示例都使用复选框或单选按钮,因此数据输入不会出现错误。但这对于这个例子来说并没有多大帮助。
那么我有什么选择可以实现我想要的目标???
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++;
SwitchUserControl();
}
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???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您问题的答案可能是用更规范的方法重新开始。 WPF 支持一个很好的导航 API,您可以使用它来构建向导。 这是一个工作示例。
关于验证,在导航 API 中,您可以使用 Page 类代替控件(来自您的示例)。您的 Page 类可以有一个属性来指示它是有效还是无效,并且您可以通过特定于页面的字段输入验证来保留字段的逻辑。
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.