简体   繁体   English

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

[英]How to create a navigation bar in xaml, which can scale with different screen resolutions?

<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>

This is the code I am using to display the nav bar , where this is written in Controller, and the navbar images are populated dynamically using Binding. 这是我用来显示导航栏的代码,该代码是在Controller中编写的,并且使用Binding动态填充了导航栏图像。

I am trying to create a nav bar, which could be used on different screen resolutions, I have tried with various methods , but it is not scaling according to different screen resolutions 我正在尝试创建一个导航栏,该导航栏可以在不同的屏幕分辨率下使用,我尝试了多种方法,但是它无法根据不同的屏幕分辨率进行缩放

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

感谢您有兴趣回答我的问题,我使用Viewbox解决了该问题。我将上述所有代码放在viewbox中,效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM