Hello,
The reason for the mouse to move to a project, the reason why all the delete buttons appear is that they bind the same Boolean value in viewmodel.
IsVisible="{Binding IsDeleteButtonVisible, Source={x:RelativeSource AncestorType={x:Type vm:TurbinesCollectionPageViewModel}}}"
If you need to show the button when the mouse is moved to an item, the Boolean value should be encapsulated into the Model class. For example, the following example class.
public class SampleModel : INotifyPropertyChanged
{
public string name { get; set; }
public bool Visible
{
get
{
return visible;
}
set
{
if (visible != value)
{
visible = value;
OnPropertyChanged();
}
}
}
private bool visible;
public event PropertyChangedEventHandler? PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string name = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
Then, necause the attributes of the control delete button display in the Model class, in the CollectionView, you can set your own binding for each entry.
IsVisible="{Binding Visible}"
Finally, you need to pass the item to ViewModel to the Item to perform visible modifications to ViewModel.
<PointerGestureRecognizer
PointerEnteredCommandParameter="{Binding .}"
PointerEnteredCommand="{Binding MouseEnterCommand, Source={x:RelativeSource AncestorType={x:Type c:MyViewModel}}}" />
<PointerGestureRecognizer
PointerExitedCommandParameter="{Binding .}"
PointerExitedCommand="{Binding MouseLeaveCommand, Source={x:RelativeSource AncestorType={x:Type c:MyViewModel}}}" />
In viewmodel:
void MouseEnter(Object o)
{
var item = (SampleModel)o;
if(item != null)
{
item.Visible = true;
}
}
void MouseLeave(Object o)
{
var item = (SampleModel)o;
if (item != null)
{
item.Visible = false;
}
}
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.