简体   繁体   中英

Binding TopItem from SwipeView Xamarin to Collectionview from Viewmodel to Visibility of View

so i dont understand how to bind properly the TargetNullValue from TopItem to the Visibility of my grid View. """

<StackLayout HorizontalOptions="Fill" BackgroundColor="Yellow">
        <AbsoluteLayout>
            <Button x:Name="exit_button" Image="exit.png" Clicked="Exit_button_Clicked"
                 AbsoluteLayout.LayoutBounds="1,0,50,50" AbsoluteLayout.LayoutFlags="PositionProportional" />
        </AbsoluteLayout>

        <swipeCardView:SwipeCardView
                x:Name="SwipeCardView"
                ItemsSource="{Binding Pictures}"
                HorizontalOptions="FillAndExpand" 
                VerticalOptions="FillAndExpand"
                BackgroundColor="Red"
                Padding="10"
                SwipedCommand="{Binding SwipedCommand}"
                DraggingCommand="{Binding DraggingCommand}"
                Threshold="{Binding Threshold}"
                SupportedSwipeDirections="{Binding SupportedDraggingDirections}"
                SupportedDraggingDirections="{Binding SupportedDraggingDirections}"
                AnimationLength="{Binding AnimationLength}"
            >
            <swipeCardView:SwipeCardView.TopItem>
                <Grid IsVisible="{Binding TopItem , Source={x:Reference SwipeCardView}, TargetNullValue={Binding TopItem}}">
                    <StackLayout>
                        <Label Text="Keine Bilder mehr vorhanden" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"
                                FontSize="Large" FontAttributes="Bold" BackgroundColor="AliceBlue"/>
                    </StackLayout>
                </Grid>
            </swipeCardView:SwipeCardView.TopItem>
            <swipeCardView:SwipeCardView.ItemTemplate>
                <DataTemplate>
                    <Grid ColumnSpacing="0" RowSpacing="0" BackgroundColor="Wheat">
                        <Grid.Resources>
                            <valueconverter:ByteArrayToImageSourceConverter x:Key="SourceConverter" />
                        </Grid.Resources>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="500" />
                        </Grid.RowDefinitions>
                        <Image  Source="{Binding Image, Converter={StaticResource SourceConverter}}" Aspect="AspectFit"  VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
                    </Grid>       
                </DataTemplate>
            </swipeCardView:SwipeCardView.ItemTemplate>
        </swipeCardView:SwipeCardView>
    </StackLayout>
</ContentPage>

"""

There is clearly a wrong Binding, as i get the Error:

'Xamarin.Forms.Grid' cannot be converted to type 'System.Boolean' 'App1.Models.Pictures' cannot be converted to type 'System.Boolean'

So as i understand from TopItem, it turn to be null, if the Collectionview or Itemsource is null that means no items are left to swipe.

I want to set the Binding to the Top item, so that if there is no item left, thant the View Should be visible

You can use a converter to converter the TopItem into a boolean value.Such as:

public class TopItemToBoolConverter : IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        TopItem top= value as TopItem;
        if(top == null)
           return false;
        else
           return true;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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