Ejemplo n.º 1
0
        private static void RestoreOriginalStyles([NotNull] ListBox listBox)
        {
            if (!(listBox.GetValue(_originalStylesProperty) is OriginalStyles originalStyles))
            {
                return;
            }

            listBox.ClearValue(_originalStylesProperty);

            listBox.Style = originalStyles.Style;
            listBox.ItemContainerStyle = originalStyles.ItemContainerStyle;
            listBox.ItemTemplate       = originalStyles.ItemTemplate;
        }
Ejemplo n.º 2
0
        public static void SetHasBindableSelectedItems(ListBox source, bool value)
        {
            SelectionChangedHandler Handler = (SelectionChangedHandler)source.GetValue(SelectionChangedHandlerProperty);

            if (value && Handler == null)
            {
                Handler = new SelectionChangedHandler(source);
                source.SetValue(SelectionChangedHandlerProperty, Handler);
            }
            else if (!value && Handler != null)
            {
                source.ClearValue(SelectionChangedHandlerProperty);
            }
        }
 public void DisposeListBox(ListBox listBox)
 {
     listBox.ClearValue(ListBox.SelectionModeProperty);
     listBox.ClearValue(ListBox.FontFamilyProperty);
     listBox.ClearValue(ListBox.FontSizeProperty);
     listBox.ClearValue(ListBox.HeightProperty);
     listBox.ClearValue(ListBox.WidthProperty);
     listBox.ClearValue(ListBox.ForegroundProperty);
 }
Ejemplo n.º 4
0
        private static void RestoreOriginalStyles([NotNull] ListBox listBox)
        {
            var originalStyles = listBox.GetValue(_originalStylesProperty) as OriginalStyles;

            if (originalStyles == null)
            {
                return;
            }

            listBox.ClearValue(_originalStylesProperty);

            listBox.Style = originalStyles.Style;
            listBox.ItemContainerStyle = originalStyles.ItemContainerStyle;
            listBox.ItemTemplate       = originalStyles.ItemTemplate;
        }
Ejemplo n.º 5
0
        private static void ListBox_MouseLeave(object sender, MouseEventArgs e)
        {
            ListBox lb = sender as ListBox;

            // Remove any previous Adorners
            AdornerInfo  prevInfo = lb.GetValue(AttachedAdornerProperty) as AdornerInfo;
            AdornerLayer layer    = AdornerLayer.GetAdornerLayer(lb);

            if (prevInfo != null)
            {
                if (layer != null)
                {
                    layer.Remove(prevInfo.Adorner);
                    lb.ClearValue(AttachedAdornerProperty);
                }
            }
        }
Ejemplo n.º 6
0
 private void UpdateSelectedItemBinding(bool remove = false)
 {
     if (_nonResponseListBox != null)
     {
         if (remove)
         {
             _nonResponseListBox.ClearValue(Selector.SelectedItemProperty);
         }
         else
         {
             var nonResponseSelectedBinding = new Binding();
             nonResponseSelectedBinding.Source = this;
             nonResponseSelectedBinding.Path   = new PropertyPath("NonResponseDto.NonResponse");
             nonResponseSelectedBinding.Mode   = BindingMode.TwoWay;
             _nonResponseListBox.SetBinding(Selector.SelectedItemProperty, nonResponseSelectedBinding);
         }
     }
 }
Ejemplo n.º 7
0
        private static void ListBox_MouseMove(object sender, MouseEventArgs e)
        {
            // Check that we are hovering on a ListBoxItem
            ListBox     lb   = sender as ListBox;
            ListBoxItem item =
                lb.ContainerFromElement(e.OriginalSource as Visual) as ListBoxItem;

            if (item == null)
            {
                return;
            }

            // Remove any previous Adorners
            AdornerInfo  prevInfo = lb.GetValue(AttachedAdornerProperty) as AdornerInfo;
            AdornerLayer layer    = AdornerLayer.GetAdornerLayer(lb);

            if (prevInfo != null)
            {
                if (prevInfo.ListItem == item)
                {
                    return;
                }
                layer.Remove(prevInfo.Adorner);
                lb.ClearValue(AttachedAdornerProperty);
            }

            // Attach new adorner to current ListBoxItem
            HoverAdorner adorner = new HoverAdorner(item);

            adorner.Container.Content         = lb.ItemContainerGenerator.ItemFromContainer(item);
            adorner.Container.ContentTemplate =
                item.FindResource("AdornerTemplate") as DataTemplate;
            layer.Add(adorner);

            AdornerInfo info = new AdornerInfo();

            info.Adorner  = adorner;
            info.ListItem = item;
            lb.SetValue(AttachedAdornerProperty, info);
        }