简体   繁体   English

Windows Phone 7中的设计器代码

[英]Designer code in Windows phone 7

我在Windows Phone 7中使用XAML创建了一个UI。我想知道该代码是否在某些文件中作为C#代码存在,如果存在,那么xaml生成的设计器代码在哪里?

If you want to create StackPanel programmatically, you can do it by "mimicking" the XAML version. 如果要以编程方式创建StackPanel ,可以通过“模仿” XAML版本来实现。

For example, the following XAML: 例如,以下XAML:

<StackPanel Foreground="White"
            Margin="12,0,0,0">
</StackPanel>

can be created with the following C# code: 可以使用以下C#代码创建:

var stackPanel = new StackPanel();
stackPanel.Foreground = new SolidColorBrush("White");
stackPanel.Margin = new Thickness(12,0,0,0);

Without knowing what your StackPanel looks like, I cannot offer you any tipss. 不知道您的StackPanel是什么样子,我无法为您提供任何提示。


I must wonder why you want to do that? 我一定想知道为什么要这么做? XAML is generally far better to design than doing it in via code. XAML通常比通过代码进行设计要好得多。 Not to mention it is cleaner and is adaptable to MVVM which is the best solution for your application. 更不用说它更干净,并且适用于MVVM,这是您的应用程序的最佳解决方案。

If you offer some more details, I can offer precise advice. 如果您提供更多详细信息,我可以提供准确的建议。

When you create code in XAML this code in C# doesn't exist in any file in your project. 在XAML中创建代码时,项目中的任何文件中都不存在C#中的代码。 The XAML code is changed to object in compilation process. XAML代码在编译过程中更改为对象。 Here You have great article about this process: 您在这里有关于此过程的精彩文章:

Article 文章

You can create GUI in code behind using objects like this: 您可以使用以下对象在代码中创建GUI:

var stackPanel = new StackPanel();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM