本文介绍了在appbar多个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怕我失去了一些东西简单在这里,但我试图把多个按钮在我的应用程序吧。

I'm afraid I'm missing something simple here, but I'm trying to put multiple buttons in my app bar.

这里的初始代码应用栏

<common:LayoutAwarePage.TopAppBar>
    <AppBar HorizontalAlignment="Left">
        <Button  x:Name="resetButton" Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Stretch" Click="resetButton_Click" />
    </AppBar>
</common:LayoutAwarePage.TopAppBar>

现在此代码的工作,但我想添加第二个按钮。

Now this code works, but I want to add a second button.

我认为这将是相当简单的事情,我尝试:

I thought that this would be fairly simple to do, I attempted:

<common:LayoutAwarePage.TopAppBar>
    <AppBar HorizontalAlignment="Left"> <!-- line 19 -->
        <Button  x:Name="resetButton" Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Stretch" Click="resetButton_Click" />
        <Button  x:Name="newButton" Content="NewButton" />  <!-- line 21 -->
    </AppBar>
</common:LayoutAwarePage.TopAppBar>



但我得到以下错误:

but I get the following errors:

The property "Content" can only be set once. (line 19)
The property "Content" can only be set once. (line 21)
Duplication assignment to the 'Content' property of the 'AppBar' object (line 21)


$ b的内容属性$ b

我觉得也许可以给的东西我失踪了 AppBar 控制。我要如何将它第二个按钮?

I think there might perhaps be something to the AppBar control that I'm missing. How do i put a second button in it?

推荐答案

简单地把一切都放在一个的StackPanel AppBar

Simply put everything in a StackPanel in AppBar

<common:LayoutAwarePage.TopAppBar>
    <AppBar HorizontalAlignment="Left"> <!-- line 19 -->
        <StackPanel Orientation="Horizontal">
            <Button  x:Name="resetButton" Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Stretch" Click="resetButton_Click" />
            <Button  x:Name="newButton" Content="NewButton" />  <!-- line 21 -->
        </StackPanel>
    </AppBar>
</common:LayoutAwarePage.TopAppBar>



为了更好地控制,您可以使用电网这将让您有两面的内容:

For better control, you could use a Grid which will allow you to have content on both sides:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="auto"/>
    </Grid.ColumnDefinitions>
    <StackPanel x:Name="LeftPanel" Orientation="Horizontal" Grid.Column="0" HorizontalAlignment="Left">
        <!-- Left Content here -->
    </StackPanel>
    <StackPanel x:Name="RightPanel" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">
        <!-- Right Content here -->
    </StackPanel>
</Grid>

这篇关于在appbar多个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 02:19