带触发器的Onplatform

时间:2017-09-05 13:54:48

标签: android ios triggers xamarin.forms

我想使用Onplatform为IOS和Android提供不同的触发器,但不知道如何或是否可能。 在IOS上我想要使用不同的边距。

以下是代码:

<Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"></RowDefinition>
                                <RowDefinition Height="Auto"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <!--left, top, right, bottom-->
                            <Label Text="{Binding article description}"
                                       FontAttributes="Bold" FontSize="13"  Margin="10,5,0,-6" Grid.Row="0" LineBreakMode="NoWrap"/>

                            <Label x:Name="Labeldishe" Text="{Binding dishe}" 
                                   FontSize="13" Margin="10,0,0,2" Grid.Row="1"/>
                            <Label Grid.Row="0" x:Name="Labelreserved"  Text="{Binding reserved}" IsVisible="false" LineBreakMode="NoWrap"/>
                            <Image x:Name="ImageReserve" Grid.Row="0" Source="checkmark.png" WidthRequest="8"  HeightRequest="8" HorizontalOptions="Start" IsVisible="False" >
                                <Image.Triggers>
                                    <DataTrigger TargetType="Image" Binding="{Binding Source={x:Reference Labelreserved},
                                   Path=Text.Length}" Value="7">
                                        <Setter Property="IsVisible" Value="true" />
                                    </DataTrigger>
                                    <DataTrigger TargetType="Image" Binding="{Binding article description}" Value="Meat">
                                        <Setter Property="Margin" Value="43,0,0,0" />
                                    </DataTrigger>
                                    <DataTrigger TargetType="Image" Binding="{Binding article description}" Value="Option">
                                        <Setter Property="Margin" Value="46,0,0,0" />
                                    </DataTrigger>
                                    <DataTrigger TargetType="Image" Binding="{Binding article description}" Value="Diet">
                                        <Setter Property="Margin" Value="40,0,0,0" />
                                    </DataTrigger>
                                    <DataTrigger TargetType="Image" Binding="{Binding article description}" Value="Fish">
                                        <Setter Property="Margin" Value="42,0,0,0" />
                                    </DataTrigger>
                                </Image.Triggers>
                            </Image>
                        </Grid>

1 个答案:

答案 0 :(得分:2)

我不完全确定,但如果支持,我认为它应该是这样的:

<DataTrigger TargetType="Image" Binding="{Binding article description}" Value="Carne">
    <Setter Property="Margin">
        <Setter.Value>
            <OnPlatform x:TypeArguments="Thickness">
                <On Platform="iOS" Value="44,0,0,0" />
                <On Platform="Android" Value="43,0,0,0" />
            </OnPlatform>
        </Setter.Value>
    </Setter>
</DataTrigger>