Hi SYarah,
you can use an attached property in ContactListingViewModel:
<ListView Grid.Row="1" Grid.Column="0"
ItemsSource="{Binding View}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
IsSynchronizedWithCurrentItem="True"
SelectedItem="{Binding Contact}"
local:ContactListingViewModel.AttPropListView="True">
...
#region attached property
public static readonly DependencyProperty AttPropListViewProperty =
DependencyProperty.RegisterAttached("AttPropListView", typeof(bool), typeof(ContactListingViewModel), new PropertyMetadata(false, OnPropChanged));
public static bool GetAttPropListView(DependencyObject obj) => (bool)obj.GetValue(AttPropListViewProperty);
public static void SetAttPropListView(DependencyObject obj, bool par) => obj.SetValue(AttPropListViewProperty, par);
private static void OnPropChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ListView lv = d as ListView;
if (lv == null) return;
lv.PreviewMouseLeftButtonDown += (s, mbe) =>
{
ContactListingViewModel vm = (ContactListingViewModel)(lv.DataContext);
vm.Contact = null;
vm.OnPropertyChanged(nameof(Contact));
};
}
#endregion
Result: