how to Make image visibility true when context action menu item is selected in listview

KarthikRamKarthikRam USMember ✭✭

I would like to change the visibility to false if the image is already appearing when user taps on user context menu item and vice versa. Please advice hoe to achieve the same.

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Bind the .IsVisible property to a bool in your ViewModel.
    The menu option would execute a command in the ViewModel.

    https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/data_binding_basics/

  • KarthikRamKarthikRam USMember ✭✭

    @ClintStLaurent Thats true. My problem is, list has many rows. Each row has its own .IsVisible property. I am only able to change the bool value of itemsource value of listview, but not the list row itself.

  • NMackayNMackay GBInsider, University ✭✭✭✭✭
    edited March 8

    @KarthikRam

    You set the visibility in your data template. Bind your IsVisible property there. I'd suggest giving the property a logical name rather than a property name. Look up data templates and binding

  • KarthikRamKarthikRam USMember ✭✭

    <ListView.ItemTemplate>



    </ListView.ItemTemplate>

    I have declared as above, where IsFavorite is boolean field present in item source of Listview. My concern is when I change IsFavorite using context action menu item, I am not able to change the visibility.

  • KarthikRamKarthikRam USMember ✭✭
    edited March 8
    <ListView.ItemTemplate>
    <DataTemplate>
    <Image Source="staron.png"  IsVisible="{Binding IsFavorite}"/>
    </DataTemplate>
    </ListView.ItemTemplate>
    
  • KarthikRamKarthikRam USMember ✭✭

    @NMackay above is my declaration in listview

  • NMackayNMackay GBInsider, University ✭✭✭✭✭
    edited March 8

    @KarthikRam

    You need to create a repo project (delete all packages and obj & bin in all projects and zip), unless we can test it's hard to help unless it's obvious.

  • SreeeeSreeee INMember ✭✭✭

    @KarthikRam I have two images like following, both are inside a viewcell.

                                   <Image
                                            Source="like.png"
                                            IsVisible="{Binding userLiked}">
                                    </Image>
                                    <Image
                                            Source="liked.png"
                                            IsVisible="{Binding userLiked}">
                                     </Image>
    

    If the {Binding userLiked} value is true i want to show the second image(liked.png) and if false show the first image(like.png). Second image is working fine for true value. But i don't know how to check the false value. I am declaring userLiked as a string.

    Can you help me.
    Thanks in advance.

Sign In or Register to comment.