gpt4 book ai didi

c# - 如何创建同一个 xaml 文件的多个部分类

转载 作者:行者123 更新时间:2023-12-01 22:24:28 25 4
gpt4 key购买 nike

我需要将代码从单个代码后面分离到多个部分类,但不知道如何实现,我在一个 msdn 代码示例中看到这是可能的,你能告诉我如何实现吗这个。

我知道我可以转向 MVVM,但现在我只需要通过分部类来组织代码。

请看下面的截图。

Partial Classes ScreenShot

最佳答案

您可以通过按照您喜欢的命名约定创建附加文件并向它们添加分部类来做到这一点。代码将像以前一样编译和工作。

MainPage.xaml.cs:

public partial class MainPage : Page {...}

MainPage.Flash.xaml.cs:

public partial class MainPage {...}

要获得附件图像中显示的内容,需要手动编辑项目文件。在文本编辑器中打开你的项目文件,看看你当前的代码是如何完成的,过程是一样的

这是您提供的图像在项目文件中的样子的示例

<ItemGroup>
<Page Include="MainPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="MainPage.ExposureValue.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.Flash.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.Focus.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.IsoSpeed.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.Shutter.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.WhiteBalance.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.Zoom.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
</ItemGroup>

关于c# - 如何创建同一个 xaml 文件的多个部分类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37108222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com