【问题标题】:UWP AdaptiveGrivew horizontalAligment not workingUWP AdaptiveGrivew 水平对齐不起作用
【发布时间】:2018-11-14 07:07:03
【问题描述】:

我创建应用程序 UWP 并使用 Mircosoft.Toolkit 的 AdaptiveGridView,但是当我在 AdaptiveGridView 中创建我的 ToggleButton 时不在中心。我该如何解决?

我的代码

<Page.Resources>
        <DataTemplate x:Key="ToggleButtonTemplate">
            <Grid>
                <ToggleButton x:Name="a" Content="{Binding Textttt}"
                        HorizontalAlignment="Center" 
                        VerticalAlignment="Center"
                        MinWidth="150" Click="Button_Click" 
                        Style="{StaticResource HeinekenToggleButtonStyle}"
                        />
            </Grid>
        </DataTemplate>
<Page.Resources>
<controls:AdaptiveGridView Name="MenuItemGrid" 
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Top"
                                   Margin="5"
                                   ItemTemplate="{StaticResource ToggleButtonTemplate}"
                                   Grid.Row="0"/>

【问题讨论】:

    标签: .net xaml uwp


    【解决方案1】:

    尝试使用 RowColumn 定义,然后设置 Grid.Column="0"Grid.Row=" 0" 用于切换按钮,如下所示:

     <Grid>
        <Grid.RowDefinitions>
         <RowDefinition Height="*"/><RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
         <ColumnDefinition Width="*"/><ColumnDefinition/>
        </Grid.ColumnDefinitions>
    
        <ToggleButton x:Name="a" Grid.Row="0" Grid.Column="0" Content="{Binding Textttt}"
                        HorizontalAlignment="Center" VerticalAlignment="Center"
                        MinWidth="150" Click="Button_Click" Style="{StaticResource  HeinekenToggleButtonStyle}"
         />
    </Grid>
    

    希望对你有所帮助。

    【讨论】:

    • 它不工作。我只想要adaptiveGridvew水平中心的项目。但是水平不工作,我不明白。
    • 我认为 ToggleButtons 在其父 Grid 中居中但是对于 AdaptiveGridView ,安装了哪个版本的工具包?请参阅此问题的旧修复程序AdaptiveGridView HorizontalAlignment not working after version 2.0.0 另外您是否通过将 AdaptiveGridView 替换为标准 GridView 对其进行了测试?
    • 我使用的是 5.0.0 版。我已阅读您的链接,但我不明白,我不知道如何解决它
    • 我尝试了 GridView 但它也不起作用
    • 如果您使用的是ver5.0没问题,它是一个旧线程并且已经修复。
    【解决方案2】:

    这按预期工作。刚开始看图我还以为有什么问题呢。最后,我意识到您希望最后两项位于最后一行的中心,而不是从一开始就显示它们。

    理论上这是可能的,但据我所知,目前还没有操作系统可以像这样工作(而且我已经为所有主要操作系统构建了应用程序)。所以如果你真的想要,你必须从头开始构建所有东西,你不能依赖任何控制,因为这不被认为是一个好的设计。

    水平对齐意味着您的控件如何放置在其容器内,而不是容器如何放置在其行内,没有任何属性会影响它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 2013-11-09
      • 2015-02-01
      • 1970-01-01
      相关资源
      最近更新 更多