在XAML中的按钮的背景中添加图像



我在网格中排列了4个按钮。我希望每个按钮能够完全显示一个按钮的大小,但是关于如何执行此操作的图像很茫然。我现在正在尝试以下方法,但是当我包含该行时。

我尝试将图像添加到网格中的第一个按钮中,但是图像太大了。我希望图像完美地覆盖按钮的大小,无论我使用的手机大小如何。

这是我的代码:

<Grid>
        <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.ColumnSpan="2" Text="Welcome," HorizontalOptions="Center" FontSize="Large" TextColor="Aqua"/>
        <Label Grid.Row="1" Grid.ColumnSpan="2" Text="User" HorizontalOptions="Center" FontSize="Large" TextColor="Aqua"/>     
        <Button Grid.Row="2" Grid.Column="0" Image="iris_light" Text="Student&#x0a;Directory" TextColor="Aqua"/>
        <Button Grid.Row="2" Grid.Column="1" Text="Executive&#x0a;Directory" TextColor="Aqua"/>
        <Button Grid.Row="3" Grid.Column="0" Text="Voting" TextColor="Aqua"/>
        <Button Grid.Row="3" Grid.Column="1" Text="Map" TextColor="Aqua">
            <Image Source="iris_light"/>
        </Button>
</Grid>

如果需要(这意味着图像属性对您来说还不够灵活(,则必须编写一个自定义渲染器。

与Windows不同,iOS和Android并非基于XAML,因此其控件的内容不能以这种方式进行编辑,因为基础OS不支持它。

解决了我的问题:

<Grid BackgroundColor="Transparent">
        <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.ColumnSpan="2" Text="Welcome," HorizontalOptions="Center" FontSize="Large" TextColor="Aqua"/>
        <Label Grid.Row="1" Grid.ColumnSpan="2" Text="User" HorizontalOptions="Center" FontSize="Large" TextColor="Aqua"/>     
        <Image Grid.Row="2" Grid.Column="0" Source="iris_light"/>
        <Button Grid.Row="2" Grid.Column="0" BackgroundColor="Transparent" Text="Student&#x0a;Directory" TextColor="Aqua"/>
        <Image Grid.Row="2" Grid.Column="1" Source="iris_light"/>
        <Button Grid.Row="2" Grid.Column="1" BackgroundColor="Transparent" Text="Executive&#x0a;Directory" TextColor="Aqua"/>
        <Image Grid.Row="3" Grid.Column="0" Source="iris_light"/>
        <Button Grid.Row="3" Grid.Column="0" BackgroundColor="Transparent" Text="Voting" TextColor="Aqua"/>
        <Image Grid.Row="3" Grid.Column="1" Source="iris_light"/>
        <Button Grid.Row="3" Grid.Column="1" BackgroundColor="Transparent" Text="Map" TextColor="Aqua"/>
    </Grid>

最新更新