【问题标题】:ListView alignment issue in Windows 8Windows 8 中的 ListView 对齐问题
【发布时间】:2013-04-05 05:55:13
【问题描述】:

我有一个奇怪的问题,我尝试了所有我知道的技巧来居中对齐放置在网格内的 ListView。无论如何,它看起来像是左对齐的。 ListView 的宽度和高度是数据绑定的。 (宽度可以取值 350 或 700,高度可以取 100 或 200,具体取决于尺寸设置。如果尺寸设置紧凑,则应为 350x100,如果正常则为 700x200)。

这是 xaml 代码

<Grid x:Name="GridPageLVPortrait" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Background="Beige" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0,584.714,0" Width="781">
   <ListView x:Name="PageLVPortrait" ItemsSource="{Binding}" CanReorderItems="True" AllowDrop="True" HorizontalAlignment="Center" SelectionMode="Single" IsSwipeEnabled="True" IsItemClickEnabled="True" SelectionChanged="PageLVPortraitSelectionChanged" ItemClick="PageLVPortraitItemClick" Height="{Binding TemplateHeight}" Width="{Binding TemplateWidth}" >
        <ListView.ItemTemplate>
             <DataTemplate>
                 <Canvas HorizontalAlignment="Center" Width="{Binding TemplateWidth}" Height="{Binding TemplateHeight}">
                     <Canvas.Background>
                          <ImageBrush ImageSource="{Binding PageBackground}"/>
                     </Canvas.Background>
                     <Image HorizontalAlignment="Center" Height="{Binding TemplateHeight}" Width="{Binding TemplateWidth}" Source="{Binding Page}" Stretch="None" Opacity="1" CacheMode="BitmapCache" />

                     <StackPanel x:Name="EditDeleteStackPanel" Width="{Binding TemplateWidth}" Height="{Binding TemplateHeight}" Opacity="0.95">
                         <Button x:Name="NoteDelete"  HorizontalAlignment="Right"   VerticalAlignment="Top" Foreground="{x:Null}" Tapped="NoteDelete_Tapped" MinWidth="50" MinHeight="50" Margin="0,0,10,0" BorderBrush="{x:Null}" >
                            <Button.Background>
                                <ImageBrush ImageSource="{Binding Delete}"/>
                            </Button.Background>
                         </Button>
                         <Button x:Name="NoteEdit"  HorizontalAlignment="Right"   VerticalAlignment="Top"   FontFamily="Segoe Script" FontSize="24" BorderBrush="{x:Null}" Tapped="NoteEdit_Tapped" Foreground="{x:Null}" MinWidth="50" MinHeight="50" Margin="0,0,10,0">
                            <Button.Background>
                                <ImageBrush ImageSource="{Binding Edit}"/>
                            </Button.Background>
                         </Button>                             
                     </StackPanel>
                 </Canvas>
             </DataTemplate>
        </ListView.ItemTemplate>
   </ListView>
</Grid>

有人可以帮忙吗?

【问题讨论】:

    标签: xaml listview windows-8 alignment


    【解决方案1】:

    我已经在具有您提供的正常尺寸约定 (700x200) 的整个页面网格中尝试了您的代码。如果我忽略网格的Margin="0,0,584.714,0",列表视图确实会居中对齐。如果您需要页面右侧的 584px,我会说最好在该宽度处放置一个网格列。

    【讨论】:

      【解决方案2】:

      我发现了问题。这是因为主网格被吐成了 4 列。而且由于这个使用列跨度,因此对齐会变得混乱。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-30
        相关资源
        最近更新 更多