/// <summary> /// <para><paramref name="VisualParent_"/>: The listbox where the MicroListboxItem will be added</para> /// </summary> /// <param name="VisualParent_"></param> public MicroListBoxItem(ListBox VisualParent_) { parent_ = VisualParent_ as ListBox; VerticalAlignment = VerticalAlignment.Stretch; this.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Stretch; Background = StateNormal; }
public Window CreateWindow() { // Create a window object and set its size to the // size of the display. mainWindow = new Window(); mainWindow.Height = SystemMetrics.ScreenHeight; mainWindow.Width = SystemMetrics.ScreenWidth; Font font = Resources.GetFont(Resources.FontResources.NinaB); // Create a list box control and add text items ListBox listBox = new ListBox(); for (int i = 0; i < 10; ++i) { string str = "Item " + i + ". Hello World."; listBox.Items.Add(new Text(font, str)); } // Add the text control to the window. mainWindow.Child = listBox; // Set the window visibility to visible. mainWindow.Visibility = Visibility.Visible; // Let the user select items with the up and down buttons. Buttons.Focus(listBox); // Get notified when the selected item was changed. listBox.SelectionChanged += new SelectionChangedEventHandler(listBox_SelectionChanged); // Get notified when a selected item was pressed // using the select button. listBox.AddHandler(Buttons.ButtonDownEvent, new ButtonEventHandler(listBox_ButtonDown), false); return mainWindow; }
/// <summary> /// <para><paramref name="VisualParent_"/>: The listbox where the MicroListboxItem will be added</para> /// </summary> /// <param name="VisualParent_"></param> public MicroListBoxItem(ListBox VisualParent_) { parent_ = VisualParent_ as ListBox; VerticalAlignment = VerticalAlignment.Stretch; Width = parent_.Width; Background = StateNormal; }
internal void SetListBox(ListBox listbox) { this._listBox = listbox; if (IsSelected && !IsSelectable) { _listBox.SelectedIndex = -1; } }
public Window CreateWindow() { // Create a window object and set its size to the // size of the display. mainWindow = new Window(); mainWindow.Height = SystemMetrics.ScreenHeight; mainWindow.Width = SystemMetrics.ScreenWidth; // Add a gradient color background to the window mainWindow.Background = new LinearGradientBrush(Colors.White, Colors.Red, 0, 0, mainWindow.Width, mainWindow.Height); Font font = Resources.GetFont(Resources.FontResources.NinaB); // Create a list box control and add text items ListBox listBox = new ListBox(); // set the width so that it fills the entire screen listBox.Child.Width = mainWindow.Width; // make the list box transparent listBox.Background = null; // make the enclosed scroll viewer transparent also // we get the scroll viewer via the child property but // need to cast it to Control in order to clear the background ((Control)listBox.Child).Background = null; for (int i = 0; i < 10; ++i) { string str = "Item " + i.ToString() + ". Hello World."; ListBoxItem item = new HighlightableTextListBoxItem(font, str); listBox.Items.Add(item); if (i > 0 && i % 4 == 0) listBox.Items.Add(new SeparatorListBoxItem()); } // Add the text control to the window. mainWindow.Child = listBox; // Set the window visibility to visible. mainWindow.Visibility = Visibility.Visible; // Let the user select items with the up and down buttons. Buttons.Focus(listBox); // Get notified when the selected item was changed. listBox.SelectionChanged += new SelectionChangedEventHandler(listBox_SelectionChanged); // Get notified when a selected item was pressed // using the select button. listBox.AddHandler(Buttons.ButtonDownEvent, new ButtonEventHandler(listBox_ButtonDown), false); return mainWindow; }
/// <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); #region Caption Text caption = new Text(Resources.GetString(Resources.StringResources.HighScore)); caption.Font = Resources.GetFont(Resources.FontResources.Consolas23); caption.ForeColor = Colors.Red; caption.SetMargin(0, 10, 0, 15); caption.TextAlignment = TextAlignment.Center; #endregion #region Score ListBox scoreListBox = new ListBox(); scoreListBox.Background = this.Background; scoreListBox.HorizontalAlignment = HorizontalAlignment.Center; foreach (ScoreRecord scoreRecord in parentApp.HighScore.Table) { ScoreItem scoreItem = new ScoreItem(scoreRecord.Name, scoreRecord.Score); scoreItem.Background = scoreListBox.Background; scoreListBox.Items.Add(scoreItem); } #endregion #region HintLabel hintTextFlow = new TextFlow(); hintTextFlow.SetMargin(0, 15, 0, 0); hintTextFlow.TextAlignment = TextAlignment.Center; UpdateHint(); #endregion StackPanel mainStack = new StackPanel(Orientation.Vertical); mainStack.HorizontalAlignment = HorizontalAlignment.Center; mainStack.Children.Add(caption); mainStack.Children.Add(scoreListBox); mainStack.Children.Add(hintTextFlow); this.Child = mainStack; this.Visibility = Visibility.Visible; Buttons.Focus(this); }
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 ListBoxItemCollection(ListBox listBox, UIElementCollection items) { _listBox = listBox; _items = items; }
/// <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); }
public Window CreateWindow() { // Create a window object and set its size to the // size of the display. mainWindow = new Window(); mainWindow.Height = SystemMetrics.ScreenHeight; mainWindow.Width = SystemMetrics.ScreenWidth; // Add a gradient color background to the window mainWindow.Background = new LinearGradientBrush(Colors.White, Colors.Red, 0, 0, mainWindow.Width, mainWindow.Height); Font normalFont = Resources.GetFont(Resources.FontResources.NinaB); Font smallFont = Resources.GetFont(Resources.FontResources.small); // Create a list box control and add text items ListBox listBox = new ListBox(); // set the width so that it fills the entire screen listBox.Child.Width = mainWindow.Width; // make the list box transparent listBox.Background = null; // make the enclosed scroll viewer transparent also // we get the scroll viewer via the child property but // need to cast it to Control in order to clear the background ((Control)listBox.Child).Background = null; // Add simple text items for (int i = 0; i < 2; ++i) { string str = "Simple text item"; Text text = new Text(normalFont, str); text.SetMargin(2); ListBoxItem item = new HighlightableListBoxItem(text); listBox.Items.Add(item); } // Add a separator listBox.Items.Add(new SeparatorListBoxItem()); // Add a text item with icon { // Create the stack panel to align the elements StackPanel stackPanel = new StackPanel(Orientation.Horizontal); // Icon Bitmap bmp = Resources.GetBitmap(Resources.BitmapResources.Clock); // Make the bitmap transparent using // the color of the top left corner pixel. // Therefore the image should not be in the Bitmap and Jpeg format // because that requires to create a copy in order to make it // transparent. Use Gif instead. bmp.MakeTransparent(bmp.GetPixel(0, 0)); Image image = new Image(bmp); image.SetMargin(2); // set a margin to separate the image // vertically center the icon within the item image.VerticalAlignment = VerticalAlignment.Center; stackPanel.Children.Add(image); // Text Text text = new Text(normalFont, "Item with a icon and text"); text.SetMargin(2); // set margin to separate the text // vertically center the icon within the item text.VerticalAlignment = VerticalAlignment.Center; stackPanel.Children.Add(text); // Create a highlightable list box item ListBoxItem item = new HighlightableListBoxItem(stackPanel); listBox.Items.Add(item); } // Add a separator listBox.Items.Add(new SeparatorListBoxItem()); // Add two items with multiple columns // use i to add a right aligned number to the first column for (int i = 0; i <= 100; i += 50) { //create the stack panel to align the elements StackPanel stackPanel = new StackPanel(Orientation.Horizontal); // Add right aligned text Text text1 = new Text(normalFont, i.ToString()); text1.Width = 30; text1.SetMargin(2); // set margin to separate the text text1.TextAlignment = TextAlignment.Right; // vertically center the icon within the item text1.VerticalAlignment = VerticalAlignment.Center; stackPanel.Children.Add(text1); // Icon Bitmap bmp = Resources.GetBitmap(Resources.BitmapResources.Audio); // Make the bitmap transparent using // the color of the top left corner pixel. // Therefore the image should not be in the Bitmap and Jpeg format // because that requires to create a copy in order to make it // transparent. Use Gif instead. bmp.MakeTransparent(bmp.GetPixel(0, 0)); Image image = new Image(bmp); image.SetMargin(2); // set a margin to separate the image // vertically center the icon within the item image.VerticalAlignment = VerticalAlignment.Center; stackPanel.Children.Add(image); // Text Text text = new Text(normalFont, "Item with multiple columns"); text.SetMargin(2); // set margin to separate the text // vertically center the icon within the item text.VerticalAlignment = VerticalAlignment.Center; stackPanel.Children.Add(text); // Create a highlightable list box item ListBoxItem item = new HighlightableListBoxItem(stackPanel); listBox.Items.Add(item); } // Add a separator listBox.Items.Add(new SeparatorListBoxItem()); // Add two multi line text item for (int i = 0; i < 2; ++i) { TextFlow textFlow = new TextFlow(); textFlow.TextRuns.Add("This is the first line.", normalFont, Colors.Black); textFlow.TextRuns.Add(TextRun.EndOfLine); textFlow.TextRuns.Add("Second line.", normalFont, Colors.Green); textFlow.TextRuns.Add(TextRun.EndOfLine); textFlow.TextRuns.Add("Third line.", smallFont, Colors.Red); textFlow.SetMargin(2); ListBoxItem item = new HighlightableListBoxItem(textFlow); listBox.Items.Add(item); } // Add the text control to the window. mainWindow.Child = listBox; // Set the window visibility to visible. mainWindow.Visibility = Visibility.Visible; // Let the user select items with the up and down buttons. Buttons.Focus(listBox); // Get notified when the selected item was changed. listBox.SelectionChanged += new SelectionChangedEventHandler(listBox_SelectionChanged); // Get notified when a selected item was pressed // using the select button. listBox.AddHandler(Buttons.ButtonDownEvent, new ButtonEventHandler(listBox_ButtonDown), false); return mainWindow; }