我正在使用 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>
字典里会有类似的内容
<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>
关于wpf - 哪种方法可能是打破大型 xaml 的最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4472298/