XAML .NET MAUI图像元素中断网格比率

7hiiyaii  于 2023-11-14  发布在  .NET
关注(0)|答案(2)|浏览(177)

我有一个网格,第一个边框内有一些边框和图像:

<Grid Margin="15" RowDefinitions=".4*,.1*,.1*,.4*">
    <Border
        Grid.Row="0"
        Grid.RowSpan="2"
        Stroke="{StaticResource DarkGray}">
        <Border.StrokeShape>
            <RoundRectangle
                CornerRadius="35,35,35,35" />
        </Border.StrokeShape>
        <Image               
            Aspect="AspectFill"
            Source="cup.jpg" />
    </Border>

我想要的是这样的:


的数据
但是如果我在网格的第一行添加Image,我会得到这样的图片:



有人能告诉我为什么图像打破布局?如果你想玩整个布局:

<Grid
    Margin="15"
    RowDefinitions=".4*,.1*,.1*,.4*">
    <Border
        Grid.Row="0"
        Grid.RowSpan="2"
        Stroke="{StaticResource DarkGray}">
        <Border.StrokeShape>
            <RoundRectangle
                CornerRadius="35,35,35,35" />
        </Border.StrokeShape>
        <Image               
            Aspect="AspectFill"
            Source="cup.jpg" />
    </Border>

    <Border
        Grid.Row="1"
        Grid.RowSpan="1"
        Stroke="{StaticResource DarkGray}">
        <Border.StrokeShape>
            <RoundRectangle
                CornerRadius="35,35,35,35" />
        </Border.StrokeShape>

    </Border>
    <Border
        Grid.Row="2"
        Grid.RowSpan="1"
        Stroke="{StaticResource DarkGray}">
        <Border.StrokeShape>
            <RoundRectangle
                CornerRadius="35,35,35,35" />
        </Border.StrokeShape>

    </Border>
    <Border
        Grid.Row="3"
        Grid.RowSpan="1"
        Stroke="{StaticResource DarkGray}">
        <Border.StrokeShape>
            <RoundRectangle
                CornerRadius="35,35,35,35" />
        </Border.StrokeShape>

    </Border>
</Grid>

kwvwclae

kwvwclae1#

我测试了你提供的代码,但它工作得很好。下面是整个.xaml代码:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp3.MainPage"
             BackgroundColor="Black">
    <Grid Margin="15"
          RowDefinitions=".4*,.1*,.1*,.4*">
        <Border Grid.Row="0"
                Grid.RowSpan="2"
                Stroke="Black">
            <Border.StrokeShape>
                <RoundRectangle CornerRadius="35,35,35,35" />
            </Border.StrokeShape>
            
            <Image Aspect="AspectFill"
                   Source="sum.jpg" />
        </Border>

       <Border Grid.Row="1" Grid.RowSpan="1" Stroke="{StaticResource DarkGray}">
            <Border.StrokeShape>
                <RoundRectangle CornerRadius="35,35,35,35" />
            </Border.StrokeShape>

       </Border>

       <Border Grid.Row="2" Grid.RowSpan="1" Stroke="{StaticResource DarkGray}">
            <Border.StrokeShape>
                <RoundRectangle CornerRadius="35,35,35,35" />
            </Border.StrokeShape>
        </Border>

       <Border Grid.Row="3" Grid.RowSpan="1" Stroke="{StaticResource DarkGray}">
            <Border.StrokeShape>
                <RoundRectangle CornerRadius="35,35,35,35" />
            </Border.StrokeShape>
            <Image Aspect="AspectFill" Source="sss.png" />
        </Border>
    </Grid>
</ContentPage>

字符串
这是effect

更新

创建一个新的干净的项目,也与其他图像(在情况下,图像本身这样做的影响)可以修复它。

w8rqjzmb

w8rqjzmb2#

没有找到问题的根本原因,但在多次重新启动和清理解决方案后,它以正确的方式显示了元素:Final Result

相关问题