C# 在xaml页面上重构2000行代码
我的页面有5个选项卡项,有超过2000行代码。是否可以将每个选项卡项的代码移动到某种模板?我如何重构这么大的页面C# 在xaml页面上重构2000行代码,c#,.net,wpf,xaml,refactoring,C#,.net,Wpf,Xaml,Refactoring,我的页面有5个选项卡项,有超过2000行代码。是否可以将每个选项卡项的代码移动到某种模板?我如何重构这么大的页面 谢谢。您可以创建新的资源字典,并将每个选项卡页面的内容放入字典中,并给它们一个键 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx
谢谢。您可以创建新的资源字典,并将每个选项卡页面的内容放入字典中,并给它们一个键
<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>
如果您想在多个选项卡上使用内容,它实际上将共享同一个静态实例,因此您必须指定是否需要它的多个实例。您可以创建新的用户控件,并将每个选项卡页面的内容放在其中
<UserControl x:Class="InstrumentServiceTabItems.ServiceHistory">
<Grid>
...
</Grid>
</UserControl>
...
然后在主页上包括以下参考:
<Page x:Class="InstrumentServicePage"
xmlns:sHistory="clr-namespace:InstrumentServiceTabItems">
<TabControl>
<TabItem>
<sHistory:ServiceHistory />
<TabItem>
</TabControl>
</Page>
将每个选项卡页放入用户控件中。