小编Den*_*nny的帖子

UWP xaml:如何显示带有图标和文字的按钮?

如何在按钮中显示图像/图标和文字?

<StackPanel Name="stackPanel" Orientation="Horizontal" Tapped="stackPanel_Tapped">
    <Button x:Name="button" FontFamily="Segoe MDL2 Assets" Content="&#xE779;" Width="50" Height="50" Background="Transparent" />
    <TextBlock Text="Grades" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

我可以在stackpanel中添加一个taplistener,但这不会使stackpanel像真正的按钮一样具有视觉效果.

我也尝试过:

<Button FontFamily="Segoe MDL2 Assets" Width="50" Height="50" x:Name="button" Content="test">
   <Image x:Name="button" Source="Assets/test.png" />
</Button>
Run Code Online (Sandbox Code Playgroud)

但我不能两次设置内容.我想要一个按钮中的文本和图标,所以当用户点击它时,它将具有像按钮一样的视觉效果.这可能吗?或者其他人有其他方法来实现这一目标吗?

谢谢阅读.

xaml imagebutton uwp uwp-xaml

11
推荐指数
1
解决办法
1万
查看次数

如何动态地将TextBlocks添加到RelativePanel?

我正在尝试动态地将TextBlocks添加到RelativePanel,但我无法找到将它们添加到彼此之下的方法.我的目标是在彼此之下动态添加六个TextBlock并交替.

它应该看起来像这样:

+---------+
| left    |
|   right |
| left    |
|   right |
| left    |
|   right |
+---------+
Run Code Online (Sandbox Code Playgroud)

我已经尝试了for循环,但是这不起作用,因为它不断地将它们添加到同一个地方而不是前一个地方..cs代码:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    for (int i = 0; i < 3; i++)
    {
        TextBlock left = new TextBlock()
        {
            Name = "left",
            Text = "left",
            Foreground = new SolidColorBrush(Colors.White)
        };
        TextBlock right = new TextBlock()
        {
            Name = "right",
            Text = "right",
            Foreground = new SolidColorBrush(Colors.White),
        };
        RelativePanel.SetBelow(left, right);
        RelativePanel.SetAlignRightWithPanel(left, true);
        relativePanel.Children.Add(left);
        relativePanel.Children.Add(right);
    } …
Run Code Online (Sandbox Code Playgroud)

c# xaml uwp uwp-xaml

3
推荐指数
1
解决办法
330
查看次数

标签 统计

uwp ×2

uwp-xaml ×2

xaml ×2

c# ×1

imagebutton ×1