public void Remove(ListBoxItem item)
 {
     _items.Remove(item);
     item.SetListBox(null);
 }
Example #2
0
        object ListBox_UpdateWindow(object obj)
        {
            maxW = 0;
            lbx = new ListBox();
            lbis = new ListBoxItem[_colors.Length];
            Random random = new Random();
            for (int i = 0; i < _colors.Length; i++)
            {
                lbis[i] = new ListBoxItem();
                Rectangle rect = new Rectangle();
                int wd = _rectW + random.Next(100);
                if (wd > maxW)
                {
                    maxW = wd;
                }
                if (uniformW)
                {
                    rect.Width = _rectW;
                }
                else
                {
                    rect.Width = wd;
                }
                rect.Height = _rectH;
                rect.Fill = new SolidColorBrush(_colors[i]);
                lbis[i].Child = rect;
                lbx.Items.Add(lbis[i]);
            }
            lbx.VerticalOffset = _vOffset;
            lbx.HorizontalOffset = _hOffset;
            lbx.SelectedIndex = index;

            lbxItemColl = lbx.Items;
            _getSelectedIndex = lbx.SelectedIndex;
            _getSelectedItem = lbx.SelectedItem;

            mainWindow.Child = lbx;

            return null;
        }
 public int IndexOf(ListBoxItem item)
 {
     return _items.IndexOf(item);
 }
 public void Insert(int index, ListBoxItem item)
 {
     _items.Insert(index, item);
     item.SetListBox(_listBox);
 }
 public bool Contains(ListBoxItem item)
 {
     return _items.Contains(item);
 }
 public int Add(UIElement element)
 {
     ListBoxItem item = new ListBoxItem();
     item.Child = element;
     return Add(item);
 }
 public int Add(ListBoxItem item)
 {
     int pos = _items.Add(item);
     item.SetListBox(_listBox);
     return pos;
 }
Example #8
0
        public void ScrollIntoView(ListBoxItem item)
        {
            VerifyAccess();

            if (!Items.Contains(item)) return;

            int panelX, panelY;
            _panel.GetLayoutOffset(out panelX, out panelY);

            int x, y;
            item.GetLayoutOffset(out x, out y);

            int top = y + panelY;
            int bottom = top + item._renderHeight;

            // Make sure bottom of item is in view
            //
            if (bottom > _scrollViewer._renderHeight)
            {
                _scrollViewer.VerticalOffset -= (_scrollViewer._renderHeight - bottom);
            }

            // Make sure top of item is in view
            //
            if (top < 0)
            {
                _scrollViewer.VerticalOffset += top;
            }
        }
        /// <summary>
        /// Creates all WPF controls of the window
        /// </summary>
        private void InitializeComponents()
        {
            this.Width = SystemMetrics.ScreenWidth;
            this.Height = SystemMetrics.ScreenHeight;
            this.Background = new SolidColorBrush(Colors.Black);

            Image logoImage = new Image(Resources.GetBitmap(Resources.BitmapResources.Logo));

            #region ListBox event handler
            Color selectedItemColor = Colors.White;
            Color unselectedItemColor = ColorUtility.ColorFromRGB(206, 206, 206);
            Brush selectedBackground = new SolidColorBrush(ColorUtility.ColorFromRGB(0, 148, 255));

            menuListBox = new ListBox();
            menuListBox.Background = this.Background;
            menuListBox.HorizontalAlignment = HorizontalAlignment.Center;

            // Event handler for menu items
            menuListBox.SelectionChanged += delegate(object sender, SelectionChangedEventArgs e)
            {
                int previousSelectedIndex = e.PreviousSelectedIndex;
                if (previousSelectedIndex != -1)
                {
                    // Change previously-selected listbox item color to unselected color
                    ((Text)menuListBox.Items[previousSelectedIndex].Child).ForeColor = unselectedItemColor;
                    menuListBox.Items[previousSelectedIndex].Background = menuListBox.Background;
                }

                // Change newly-selected listbox item color to selected color and background
                ((Text)menuListBox.Items[e.SelectedIndex].Child).ForeColor = selectedItemColor;
                menuListBox.Items[e.SelectedIndex].Background = selectedBackground;
            };
            #endregion

            #region Menu Items
            // Menu items from resources
            string[] menuItems = new string[4] { Resources.GetString(Resources.StringResources.RookieLevel),
                                                 Resources.GetString(Resources.StringResources.AdvancedLevel),
                                                 Resources.GetString(Resources.StringResources.ExtremeLevel),
                                                 Resources.GetString(Resources.StringResources.ViewHighScore)};
            // Add items into listbox
            foreach(string item in menuItems)
            {
                Text itemText = new Text(Resources.GetFont(Resources.FontResources.NinaB), item);
                itemText.Width = this.Width - 40;
                itemText.ForeColor = unselectedItemColor;
                itemText.TextAlignment = TextAlignment.Center;
                itemText.SetMargin(5);

                ListBoxItem listBoxItem = new ListBoxItem();
                listBoxItem.Background = menuListBox.Background;
                listBoxItem.Child = itemText;

                menuListBox.Items.Add(listBoxItem);
            }

            menuListBox.SelectedIndex = 0;
            #endregion

            // Add all controls to stack panel
            StackPanel mainStackPanel = new StackPanel(Orientation.Vertical);
            mainStackPanel.Children.Add(logoImage);
            mainStackPanel.Children.Add(menuListBox);

            this.Child = mainStackPanel;

            this.Visibility = Visibility.Visible;
            Buttons.Focus(menuListBox);
        }