本文介绍了[U8.1]如何通过UW8和8.1中的代码实现Xaml控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Windows应用开发的新手, 

< Pivot x:Name =" mypivots" &NBSP;的SelectionChanged = QUOT; mypivots_SelectionChanged" >

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < PivotItem  Header =" First" >

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < StackPanel x:Name =" first"背景= QUOT;橙"  高度=" 100">< / StackPanel>&
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / PivotItem>

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < PivotItem Header =" Second">

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < StackPanel x:Name =" second"背景= QUOT;绿色"  高度=" 100">< / StackPanel>&
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / PivotItem>

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / Pivot>

                <PivotItem  Header="First" >
                <StackPanel x:Name="first" Background="Orange"  Height="100"></StackPanel>
            </PivotItem>
                <PivotItem Header="Second">
                <StackPanel x:Name="second" Background="Green"  Height="100"></StackPanel>
            </PivotItem>
            </Pivot>

我想通过代码(c#)创建这个xaml代码。我很困惑。

i want to create this xaml code through code behind (c#).I am so confused.




推荐答案

欢迎
到开发环球Windows应用论坛!

请阅读粘贴帖子,尤其是

发布指南:主题行标签

Windows 10 SDK和工具的已知问题 
 

Please read the sticky posts, especially theGuide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools  

请自行帮助为标题添加标签。

Please help add tag to title by yourself.

如果您使用C#语言进行开发,那么所有XAML控件都是C#对象,它们与代码隐藏C#对象相同。

If you’re developing with C# language, then all the XAML controls are the C# objects, they’re the same with the code-behind C# object.

所以,如果要通过编程将XAML控件添加到XAML页面的根面板,可以初始化对象并将其添加到特定面板孩子喜欢以下内容:

So, If you want to add a XAML control to XAML page’s root panel by programming, you could initialize an object and add it to the specific panel’s children like the following:

<Page
    x:Class="App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid x:Name="root" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    </Grid>
</Page>


Pivot pivot = new Pivot();
PivotItem item = new PivotItem();
item.Header = "item1";
pivot.Items.Add(item);
root.Children.Add(pivot);

最好的问候,

Xavier Eoro

Xavier Eoro


这篇关于[U8.1]如何通过UW8和8.1中的代码实现Xaml控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 00:27