如何避免列表视图中的Selected Item对象被击中两次?

时间:2019-05-08 10:19:29

标签: c# xamarin

所选项目对象被击中两次。如何解决它。我在堆栈布局中使用两个listview都引用同一个对象。

<ListView x:Name="listview"ItemsSource="{Binding NewDeviceSessionList}"SelectedItem="{Binding DeviceSession, Mode=TwoWay}">

 private DeviceSession _deviceSession;

 public DeviceSession DeviceSession { 
 get => _deviceSession; 
 set=> SetProperty(ref _deviceSession, value); 
 CallSome();
 }

 private void CallSome()
 {
  if(DeviceSession==null) return;
 }

1 个答案:

答案 0 :(得分:0)

使用以下代码修复

   public DeviceSession DeviceSession
    {
        get => _deviceSession;
        set
        {
            if (_deviceSession != value)
            {
                SetProperty(ref _deviceSession, value);
                CallSome();
            }
        }
    }