public void List_SelectionChanged(object sender, EventArgs e)
 {
     if (!IgnoreChanges)
     {
         IgnoreChanges    = true;
         FilterProperties = new FilterItemProperites {
             Ids = ItemsList.GetSelectedIds()
         };
         IgnoreChanges = false;
     }
 }
        public void Dispose()
        {
            BindingOperations.ClearBinding(this, ItemsListProperty);
            BindingOperations.ClearBinding(this, FilterPropertiesProperty);
            if (ItemsList != null)
            {
                ItemsList.SelectionChanged -= List_SelectionChanged;
                ItemsList = null;
            }

            FilterProperties = null;
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (Template != null)
            {
                var closeCommand = isPrimaryFilter ? mainModel.CloseSubFilterCommand : mainModel.CloseAdditionalFilterCommand;
                MenuHost = Template.FindName("PART_MenuHost", this) as FrameworkElement;
                if (MenuHost != null)
                {
                    MenuHost.InputBindings.Add(new KeyBinding(closeCommand, new KeyGesture(Key.Back)));
                    MenuHost.InputBindings.Add(new KeyBinding(closeCommand, new KeyGesture(Key.Escape)));
                    MenuHost.InputBindings.Add(new XInputBinding(closeCommand, XInputButton.B));
                }

                ButtonBack = Template.FindName("PART_ButtonBack", this) as ButtonBase;
                if (ButtonBack != null)
                {
                    ButtonBack.Command = closeCommand;
                }

                ButtonClear = Template.FindName("PART_ButtonClear", this) as ButtonBase;
                if (ButtonClear != null)
                {
                    ButtonClear.Command = new RelayCommand <object>(a =>
                    {
                        FilterProperties = null;
                        IgnoreChanges    = true;
                        ItemsList?.SetSelection(null);
                        IgnoreChanges = false;
                    });
                    BindingTools.SetBinding(ButtonClear,
                                            FocusBahaviors.FocusBindingProperty,
                                            mainModel,
                                            nameof(mainModel.SubFilterVisible));
                }

                ItemsHost = Template.FindName("PART_ItemsHost", this) as ItemsControl;
                if (ItemsHost != null)
                {
                    AssignItemListPanel(ItemsHost);
                    BindingTools.SetBinding(
                        ItemsHost,
                        ItemsControl.ItemsSourceProperty,
                        this,
                        nameof(ItemsList));
                }
            }
        }