简体   繁体   中英

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.

For example, the following XAML:

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

can be created with the following C# code:

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.


I must wonder why you want to do that? XAML is generally far better to design than doing it in via code. Not to mention it is cleaner and is adaptable to MVVM which is the best solution for your application.

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. The XAML code is changed to object in compilation process. Here You have great article about this process:

Article

You can create GUI in code behind using objects like this:

var stackPanel = new StackPanel();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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