Hi
I have an image in a ListView that have Source property . How can I change Source property when another image in same ListView tapped ?
I want Tap on ffimageLoading in CarouselView and Source property of Image in StackLayout will change . both CarouselView and StackLayout are in CollectionView
Model class needs to implement INotifyPropertyChanged
.
public class FPostModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string name = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } private string _likedImage; public string likedImage { get { return _likedImage; } set { _likedImage = value; OnPropertyChanged(); } } }
Put likeTapCommand
inside model class FPostModel
not HomeViewModel
.
Change likedImage
in callback method of likeTapCommand
.
Answers
anyone can help ?
@mmsh Could you post the complete code (viewmodel )?
Hi @ColeX
this is my ViewModel
But I want to change property in Code Behind
The easiest way is to use messaging center , send the message in
Like
method and receive in the model which own the propertyLikedImage
, modify the data when tapping on ffimageLoading in CarouselView .Thanx for yor reply .
LikedImage
owned by an ObservableCollection that name is Post . How can I receive message and pass it to LikedImage that is in an ObservableCollection and save ?Can you help me @ColeX
Model class needs to implement
INotifyPropertyChanged
.Put
likeTapCommand
inside model classFPostModel
notHomeViewModel
.Change
likedImage
in callback method oflikeTapCommand
.Hi @ColeX
Thanx for your reply . Excuse me for delay
BindingContext of CollectionView is HomeViewModel and in it I Load data when page is Call and Image control read likedImage from an ObservableCollection in that . How can I change likedImage in Model when BindingContext is ViewModel ?
as @ColeX said I implemented INotifyPropertyChanged in Model class (FPostModel) and change ExecuteLikeTap command in ViewModel
`
protected void ExecuteLikeTap(object l)
{
var lbl = l as Label;
`
But fore retrieving Post Id I used a hidden Lable in XAML and bind Post.id to it's text and in TapGestureRecognizer send it as parameter . I believe it is wrong way . Any body can help me in this case ?