如何在xaml中创建导航栏,可以使用不同的屏幕分辨率进行缩放?

时间:2014-07-10 21:28:12

标签: c# windows xaml windows-store-apps

<Grid
    Width="auto">
    <Grid.RowDefinitions>
        <RowDefinition Height="100"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid
        Grid.Row="0"
        Grid.Column="0"
        Grid.ColumnSpan="4"
        HorizontalAlignment="Stretch"
        Width="auto" Background="Red"
        >
        <ItemsControl ItemsSource="{Binding Buttons}"  HorizontalAlignment="Stretch">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" 
                                HorizontalAlignment="Stretch"
                                Background="Green"
                                ></StackPanel>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate >
                <DataTemplate>
                    <Button  
                        BorderThickness="0"
                        Background="Blue" 
                        HorizontalAlignment="Stretch"
                        Command="{Binding NavigateCommand}" 
                        Margin="0,0,120,0" 
                        Width="auto"
                       >
                        <Image Source="{Binding Image}" HorizontalAlignment="Stretch"></Image>
                    </Button>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</Grid>

这是我用来显示导航栏的代码,其中这是用Controller编写的,导航栏图像是使用Binding动态填充的。

我正在尝试创建一个导航栏,可以在不同的屏幕分辨率上使用,我已经尝试了各种方法,但它没有根据不同的屏幕分辨率进行缩放

2 个答案:

答案 0 :(得分:0)

也许您打算删除Grid.ColumnSpan="4"

答案 1 :(得分:0)

感谢您有兴趣回答我的问题,我使用Viewbox解决了问题。我将以上所有代码放在了视图框中,并且它运行良好。