c# - 如何从其他 XAML 在 UWP 透视中添加元素
问题描述
我有这个带有一个 Pivot 元素的 XAML 代码。我想添加元素而不是TextBlock
其他 XAML 中的元素。这是我的代码:
<Grid>
<Grid RequestedTheme="Default">
<Grid.RowDefinitions>
<RowDefinition Height="23*"/>
<RowDefinition Height="978*"/>
</Grid.RowDefinitions>
<Pivot Grid.RowSpan="2">
<PivotItem Header="All">
<TextBlock Text="All works here" />
</PivotItem>
<PivotItem Header="Important">
<TextBlock Text="Important works goes here" />
</PivotItem>
<PivotItem Header="Pending">
<TextBlock Text="Pending works goes here" />
</PivotItem>
<PivotItem Header="Done">
<TextBlock Text="Done works goes here" />
</PivotItem>
</Pivot>
</Grid>
</Grid>
有人可以告诉我我该怎么做吗?
解决方案
根据您的评论,您希望将自定义控件添加到 PivotItem 中。我不知道您的自定义控件是什么样的,所以我自己制作了一个自定义控件来向您展示它应该如何工作。您可以将其替换为您自己的自定义控件。
主页代码:
<Grid RequestedTheme="Default">
<Grid.RowDefinitions>
<RowDefinition Height="23*"/>
<RowDefinition Height="978*"/>
</Grid.RowDefinitions>
<Pivot Grid.RowSpan="2">
<PivotItem Header="All">
<TextBlock Text="All works here" />
</PivotItem>
<PivotItem Header="Important">
<!--this is the custom control I made-->
<local:CustomTextBox x:Name="MycustomControl"/>
</PivotItem>
<PivotItem Header="Pending">
<TextBlock Text="Pending works goes here" />
</PivotItem>
<PivotItem Header="Done">
<TextBlock Text="Done works goes here" />
</PivotItem>
</Pivot>
</Grid>
自定义控件的代码:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox x:Name="InputBox" Width="600"/>
<Button x:Name="ClickButton" Content="Please Click" Click="ClickButton_Click" Grid.Row="1"/>
<TextBlock x:Name="DisplayTextBlock" Grid.Row="2"/>
</Grid>
它是一个简单的自定义控件,它结合了一个 TextBox、一个按钮和一个 TextBlock。
如果您仍有疑问,请告诉我
推荐阅读
- python - 未能使用 Seaborn 在每个画布中绘制一个图形以获取 pandas 中的 groupby 数据
- parsing - 在 shift reduce 解析中,为什么句柄最终总是出现在堆栈顶部而不是内部?
- javascript - 无法链接到 Express 提供的 HTML 中的样式表或脚本
- node.js - Mongodb 时间间隔查询类似sql
- flutter - “num”类型的值不能分配给“T”类型的变量
- html - angular (2021) formGroup 需要一个 FormGroup 实例。请传入一个
- django - GeoDjango 安装尝试#5....斗争仍在继续
- c++ - 使用向量时是否有索引 getter 方法?
- python - 如何读取子文件夹中的 json 文件?
- php - 为 SOAP Web 服务设置正确(询问)密钥 AES-256 加密的问题