Vic*_*Vic 2 wpf xaml large-files
我正在使用WPF框架3.5开发桌面项目.
这个应用程序有很多屏幕,但所有这些都是使用单个用户控件(基本上是一个包含在类中的堆栈面板和一些额外的逻辑)呈现的,我所做的就是根据用户选择推送和弹出屏幕.
现在,所有屏幕(基本上都是堆栈面板)都保留在一个xaml文件中,这个文件变得非常大,而且维护和更新变得非常困难.
所以我想也许我可以为应用程序上的每个屏幕创建用户控件,这会破坏xaml文件,使其更容易使用,但我不确定这是最好的方法还是推荐的方法,那是为什么我想知道其他人如何处理这个问题.
谢谢!
为什么不使用资源字典来分解Xaml
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml" />
<ResourceDictionary Source="Dictionary2.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<StackPanel>
<ContentControl Content="{StaticResource StackPanel1}" />
<ContentControl Content="{StaticResource StackPanel2}" />
</StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
这些词典的内容与此类似
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel x:Key="StackPanel1">
<Button />
<Button />
</StackPanel>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)