在按钮或框架内显示小图像

时间:2019-05-16 10:56:19

标签: c# xaml xamarin.forms

我需要在FrameButton内显示一个小图像,但是Image所使用的图像要比我的Button / Frame大,何时我尝试使用Frame来做到这一点,它仅显示Image不会显示Button,问题是Image太大了。我该如何解决。

使用Button

<Frame BackgroundColor="#40000000" BorderColor="#FFFFFF" CornerRadius="6" Padding="0" Grid.Row="1" Grid.Column="1">
                <Grid>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="0.01*"/>
                            <RowDefinition Height="0.15*"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="0.01*"/>
                            <ColumnDefinition Width="0.15*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Button Image="sobremesa.png" BackgroundColor="Black" Grid.Row="1" Grid.Column="1" x:Name="Ingredient"/>
                    </Grid>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="0.2*"/>
                            <RowDefinition Height="2.8*"/>
                            <RowDefinition Height="0.7*"/>
                            <RowDefinition Height="0.7*"/>
                            <RowDefinition Height="0.2*"/>
                        </Grid.RowDefinitions>
                        <Image Source="https://i.imgur.com/066Iazn.png" Grid.Row="1" x:Name="CategoryImage"/>
                        <Label Text="Melão c/ Presunto" VerticalTextAlignment="Start" TextColor="White" HorizontalTextAlignment="Center" Grid.Row="2"/>
                        <Label Text="6.90€" VerticalTextAlignment="Start" TextColor="White" HorizontalTextAlignment="Center" Grid.Row="3"/>
                    </Grid>
                </Grid>
                <Frame.GestureRecognizers>
                    <TapGestureRecognizer 
                        Tapped="TapGestureRecognizer_Tapped"
                        NumberOfTapsRequired="1"/>
                </Frame.GestureRecognizers>
</Frame>

使用Frame

<Frame BackgroundColor="#40000000" BorderColor="#FFFFFF" CornerRadius="6" Padding="0" Grid.Row="1" Grid.Column="1">
                <Grid>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="0.01*"/>
                            <RowDefinition Height="0.15*"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="0.01*"/>
                            <ColumnDefinition Width="0.15*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Frame Grid.Row="1" Grid.Column="1" BackgroundColor="Black" x:Name="Ingredient">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="0.1*"/>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="0.1*"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="0.1*" />
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="0.1*"/>
                                </Grid.ColumnDefinitions>
                                <Image Source="sobremesa.png" Grid.Row="1" Grid.Column="1"/>
                            </Grid>
                        </Frame>
                    </Grid>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="0.2*"/>
                            <RowDefinition Height="2.8*"/>
                            <RowDefinition Height="0.7*"/>
                            <RowDefinition Height="0.7*"/>
                            <RowDefinition Height="0.2*"/>
                        </Grid.RowDefinitions>
                        <Image Source="https://i.imgur.com/066Iazn.png" Grid.Row="1" x:Name="CategoryImage"/>
                        <Label Text="Melão c/ Presunto" VerticalTextAlignment="Start" TextColor="White" HorizontalTextAlignment="Center" Grid.Row="2"/>
                        <Label Text="6.90€" VerticalTextAlignment="Start" TextColor="White" HorizontalTextAlignment="Center" Grid.Row="3"/>
                    </Grid>
                </Grid>
                <Frame.GestureRecognizers>
                    <TapGestureRecognizer 
                        Tapped="TapGestureRecognizer_Tapped"
                        NumberOfTapsRequired="1"/>
                </Frame.GestureRecognizers>
</Frame>

With <code>Button</code> With <code>Frame</code>

我试图显示在Image中的Frame在子Frame中。 请记住,当我尝试使用Frame显示时,它不会显示Image

0 个答案:

没有答案