我的页面有 5 个选项卡项,有两千多行代码。是否可以将每个选项卡项的代码移动到某种模板?这么大的页面如何重构?
谢谢。
最佳答案
您始终可以创建新的资源字典并将每个选项卡页的内容放入其中,并给它们一个 key 。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Key="tabPage1">
<!-- your controls here-->
</Grid>
</ResourceDictionary>
然后用该键引用。
<TabControl>
<TabItem Content="{StaticResource tabPage1}"/>
</TabControl>
如果您想在多个选项卡上使用内容,它实际上会共享同一个静态实例,因此您必须指定是否需要它的多个实例。
关于c# - 重构两千行代码xaml页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16038606/