Represents gallery item
Inheritance: System.Windows.Controls.ListBoxItem, IKeyTipedControl
Beispiel #1
0
        /// <summary>
        /// Adds the text content of a node to the object.
        /// </summary>
        /// <param name="text">The text to add to the object</param>
        public void AddText(string text)
        {
            GalleryItem item = new GalleryItem();

            item.Content = text;
            Items.Add(item);
        }
Beispiel #2
0
        /// <summary>
        /// When overridden in a derived class, is invoked whenever
        /// application code or internal processes call ApplyTemplate
        /// </summary>
        public override void OnApplyTemplate()
        {
            if (textBox != null)
            {
                textBox.TextChanged      -= OnTextBoxTextChanged;
                textBox.PreviewKeyDown   -= OnTextBoxPreviewKeyDown;
                textBox.SelectionChanged -= OnTextBoxSelectionChanged;
            }
            textBox = GetTemplateChild("PART_TextBox") as System.Windows.Controls.TextBox;
            if (textBox != null)
            {
                textBox.TextChanged      += OnTextBoxTextChanged;
                textBox.PreviewKeyDown   += OnTextBoxPreviewKeyDown;
                textBox.SelectionChanged += OnTextBoxSelectionChanged;
                textBox.Text              = CurrentText;
            }

            selectedGalleryItem = GetTemplateChild("PART_GalleryItem") as GalleryItem;
            fakeImage           = GetTemplateChild("PART_FakeImage") as Image;
            contentBorder       = GetTemplateChild("PART_ContentBorder") as Border;
            if (contextMenu != null)
            {
                contextMenu.PlacementTarget = contentBorder;
            }
        }
Beispiel #3
0
        // Coerce selected item
        private static object CoerceSelectedItem(DependencyObject d, object basevalue)
        {
            Gallery gallery = (Gallery)d;

            if (!gallery.Selectable)
            {
                GalleryItem galleryItem = (GalleryItem)gallery.ItemContainerGenerator.ContainerFromItem(basevalue);

                if (basevalue != null && galleryItem != null)
                {
                    galleryItem.IsSelected = false;
                }

                return(null);
            }

            return(basevalue);
        }
Beispiel #4
0
        /// <summary>
        /// Handles Command changed
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            GalleryItem  control = d as GalleryItem;
            EventHandler handler = control.OnCommandCanExecuteChanged;

            if (e.OldValue != null)
            {
                (e.OldValue as ICommand).CanExecuteChanged -= handler;
            }
            if (e.NewValue != null)
            {
                handler = new EventHandler(control.OnCommandCanExecuteChanged);
                control.canExecuteChangedHandler            = handler;
                (e.NewValue as ICommand).CanExecuteChanged += handler;

                //RoutedUICommand cmd = e.NewValue as RoutedUICommand;
                //if ((cmd != null) && (control.Content==null)) control.Content = cmd.Text;
            }
            control.UpdateCanExecute();
        }
Beispiel #5
0
 private double GetItemWidth()
 {
     if (double.IsNaN(ItemWidth) && (listBox != null) && (listBox.Items.Count > 0))
     {
         GalleryItem item    = (listBox.ItemContainerGenerator.ContainerFromItem(listBox.Items[0]) as GalleryItem);
         bool        useHack = false;
         if (item == null)
         {
             useHack = true;
             RemoveLogicalChild(listBox.Items[0]);
             item        = new GalleryItem();
             item.Width  = ItemWidth;
             item.Height = ItemHeight;
             if (ItemContainerStyle != null)
             {
                 item.Style = ItemContainerStyle;
             }
             if (ItemTemplate != null)
             {
                 item.Content     = ItemTemplate;
                 item.DataContext = listBox.Items[0];
             }
             else
             {
                 item.Content = listBox.Items[0];
             }
         }
         item.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
         if (useHack)
         {
             item.Content = null;
             AddLogicalChild(listBox.Items[0]);
         }
         return(item.DesiredSize.Width);
     }
     return(ItemWidth);
 }
 private void CancelPreview(GalleryItem galleryItem)
 {
     Trace.WriteLine(string.Format("CancelPreview: {0}", galleryItem));
 }
 private double GetItemWidth()
 {
     if (double.IsNaN(ItemWidth) && (listBox != null) && (listBox.Items.Count > 0))
     {
         GalleryItem item = (listBox.ItemContainerGenerator.ContainerFromItem(listBox.Items[0]) as GalleryItem);
         bool useHack = false;
         if (item == null)
         {
             useHack = true;
             RemoveLogicalChild(listBox.Items[0]);
             item = new GalleryItem();
             item.Width = ItemWidth;
             item.Height = ItemHeight;
             if (ItemContainerStyle != null) item.Style = ItemContainerStyle;
             if (ItemTemplate != null)
             {
                 item.Content = ItemTemplate;
                 item.DataContext = listBox.Items[0];
             }
             else item.Content = listBox.Items[0];
         }
         item.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
         if (useHack)
         {
             item.Content = null;
             AddLogicalChild(listBox.Items[0]);
         }
         return item.DesiredSize.Width;
     }
     return ItemWidth;
 }
 /// <summary>
 /// Adds the text content of a node to the object. 
 /// </summary>
 /// <param name="text">The text to add to the object</param>
 public void AddText(string text)
 {
     GalleryItem item = new GalleryItem();
     item.Content = text;
     Items.Add(item);
 }