如何在wpf c# 中分离单独的函数(选项卡)?
我有我的 Mainwindow 类、Mainwindow.xaml 和 Mainwindow.cs。问题是我有 4 个选项卡,每个选项卡都有自己的功能。所有这些都在我的 Mainwindow.xaml 和 cs 上。有没有办法将它们分开,因为我的 Mainwindow.Xaml 变得越来越大,然后我对这么多代码感到困惑。我要问的可能有点基本,但我不知道如何与 xaml 分开,因为我想保持布局不变。
希望我解释得很好。
提前致谢
I have got my Mainwindow class , Mainwindow.xaml and Mainwindow.cs. Problem is I have got 4 tabs and each tab has own functions. All this is on my Mainwindow.xaml and cs. Is there any way of separating them because my Mainwindow.Xaml is getting bigger and bigger and then I get confuse with so much code.Probably is bit basic what I am asking but I dont know how to do separate with xaml, becasue I want to keep the layout as it is.
Hope I have explained well.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为每个选项卡使用不同的
UserControls
。每个选项卡都有相应的UserControl
,如下所示:这里是有关如何在 WPF 中创建和使用
UserControl
的更多文档。还有一个关于 att WindowsClient 的视频,讨论 “如何在 WPF 中创建用户控件” 。当您对 WPF 的基础感到满意时,您可能需要考虑研究 MVVM 模式,您可以 在 MSDN 上阅读相关内容,有一些框架可用于使 MVVM 更容易,例如 PRISM。但他们往往倾向于做更复杂的事情。
首先将选项卡分成不同的用户控件,然后从那里开始。
You can use different
UserControls
for each tab. And each tab has the correspondingUserControl
like this:<myControls:userProfileTabControl />
Here is some more documentation on how to create and use a
UserControl
in WPF. There is also a video over att WindowsClient that talks about "How to Create a User Control in WPF".When you feel comfortable with the basis of WPF you might want to consider looking into the MVVM pattern, you can read about it over at MSDN, there are frameworks to use to make MVVM easier such as PRISM. But often they tend to do things a bit more complicated.
Start off by seperating your tabs into different User Controls and go from there.
如果它是一个小型应用程序,您可以为每个选项卡的内容创建一个用户控件,然后在那里实现所有逻辑。然后,您可以将用户控件嵌入到每个选项卡中。
如果应用程序可以增长,或者您想在其中添加更多顺序,请查看PRISM 框架
If it's a small application, you can create a User control for each tab's content, and then implement all the logic there. You then embed your user controls in each tab.
If the application can grow, or you want to put a bit more of order in there, take a look to The PRISM Framework