Пример #1
0
        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);
        }
 protected override void OnAttached()
 {
     base.OnAttached();
     _previewKeyDownEventDelegate = new KeyEventHandler(AssociatedObject_previewKeyDown);
     _listBox = AssociatedObject as ListBox;
     _listBox.AddHandler(Keyboard.PreviewKeyDownEvent, _previewKeyDownEventDelegate);
 }
Пример #3
0
        protected void HookScrollEventsTo(ListBox Lb)
        {
            Lb.AddHandler(ListBox.ManipulationCompletedEvent, (EventHandler <ManipulationCompletedEventArgs>)LB_ManipulationCompleted, true);
            sb = (ScrollBar)FindElementRecursive(Lb, typeof(ScrollBar));
            sv = (ScrollViewer)FindElementRecursive(Lb, typeof(ScrollViewer));

            if (sv != null)
            {
                // Visual States are always on the first child of the control template
                FrameworkElement element = VisualTreeHelper.GetChild(sv, 0) as FrameworkElement;
                if (element != null)
                {
                    VisualStateGroup group = FindVisualState(element, "ScrollStates");
                    if (group != null)
                    {
                        group.CurrentStateChanging += new EventHandler <VisualStateChangedEventArgs>(group_CurrentStateChanging);
                    }
                    VisualStateGroup vgroup = FindVisualState(element, "VerticalCompression");
                    if (vgroup != null)
                    {
                        vgroup.CurrentStateChanging += new EventHandler <VisualStateChangedEventArgs>(vgroup_CurrentStateChanging);
                    }
                }
            }
        }
Пример #4
0
        public void AutoScrollToSelectedItem_Causes_Scroll_To_SelectedItem()
        {
            var items = new ObservableCollection <string>
            {
                "Foo",
                "Bar",
                "Baz"
            };

            var target = new ListBox
            {
                Template = Template(),
                Items    = items,
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            var raised = false;

            target.AddHandler(Control.RequestBringIntoViewEvent, (s, e) => raised = true);

            target.SelectedIndex = 2;

            Assert.True(raised);
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public SearchResult()
        {
            InitializeComponent();

            // TODO ハンドラ登録のやり方が分からず、ネットで調査した内容をそのまま利用している
            m_SearchResultListBox = this.Find <ListBox>("SearchResultListBox");
            m_SearchResultListBox.AddHandler(PointerPressedEvent, DoDrag, handledEventsToo: true);
        }
Пример #6
0
        public WordView()
        {
            InitializeComponent();
            ListBox.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler((sender, args) => args.Handled = false), true);
            StreamResourceInfo closedhand = System.Windows.Application.GetResourceStream(new Uri("Images/closedhand.cur", UriKind.Relative));

            Debug.Assert(closedhand != null);
            _closedHandCursor = new Cursor(closedhand.Stream);
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public PlaylistControl()
        {
            InitializeComponent();

            SetupDnd();

            // TODO ハンドラ登録のやり方が分からず、ネットで調査した内容をそのまま利用している
            m_PlaylistControlListBox = this.Find <ListBox>("PlaylistControlListBox");
            m_PlaylistControlListBox.AddHandler(PointerPressedEvent, DoDrag);
        }
 public AlarmClockView(ListBox list)
 {
     InitializeComponent();
     _list = list;
     //Decorator border = VisualTreeHelper.GetChild(list, 0) as Decorator;
     //if (border != null)
     //{
     //    (border.Child as ScrollViewer).AddHandler(ScrollViewer.ScrollChangedEvent, new RoutedEventHandler(ScrollViewer_ScrollChanged1));
     //}
     list.AddHandler(ScrollViewer.ScrollChangedEvent, new RoutedEventHandler(ScrollViewer_ScrollChanged1));
 }
        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);
        }
Пример #10
0
    private static void OnChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ListBox listBox = d as ListBox;

        if ((bool)e.NewValue)
        {
            listBox.AddHandler(ListBoxItem.SelectedEvent, (RoutedEventHandler)OnListBoxItemSelected, true);
        }
        else
        {
            listBox.RemoveHandler(ListBoxItem.SelectedEvent, (RoutedEventHandler)OnListBoxItemSelected);
        }
    }
        public TweetAreaSuggestionPopup()
        {
            InitializeComponent();
            Items = new ObservableCollection <SuggestionItem>();

            Popup = new Popup
            {
                Child = this,
                IsLightDismissEnabled = false,
                Opacity = 1
            };

            ListBox.AddHandler(KeyDownEvent, new KeyEventHandler(ListBox_KeyDown), true);
        }
Пример #12
0
 public SuggestableTextBox()
 {
     _candidateList = new ListBox {
         Background = Brushes.White
     };
     _suggestListPopup = new Popup
     {
         IsOpen    = false,
         Child     = _candidateList,
         StaysOpen = true,
         MaxHeight = 420,
         Width     = 250
     };
     _candidateList.PreviewKeyDown += (_, e) => OnPreviewKeyDown(e);
     _candidateList.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnListMouseDown), true);
 }
Пример #13
0
        private void loadAlbums()
        {
            this._albumsList.Items.Clear();
            _albumsList.DisplayMemberPath = "Text";

            List <Album> albumsList = api.getAllAlbums();

            foreach (Album album in albumsList)
            {
                ListViewItem name = new ListViewItem();
                name.Content = album.name;

                _albumsList.Items.Add(name);
            }

            _albumsList.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(AlbumOpenClick), true);
        }
Пример #14
0
        public void Clicking_Item_Should_Raise_BringIntoView_For_Correct_Control()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                // Issue #3934
                var items  = Enumerable.Range(0, 10).Select(x => $"Item {x}").ToArray();
                var target = new ListBox
                {
                    Template     = ListBoxTemplate(),
                    Items        = items,
                    ItemTemplate = new FuncDataTemplate <string>((x, _) => new TextBlock {
                        Height = 10
                    }),
                    SelectionMode      = SelectionMode.AlwaysSelected,
                    VirtualizationMode = ItemVirtualizationMode.None,
                };

                Prepare(target);

                // First an item that is not index 0 must be selected.
                _mouse.Click(target.Presenter.Panel.Children[1]);
                Assert.Equal(1, target.Selection.AnchorIndex);

                // We're going to be clicking on item 9.
                var item   = (ListBoxItem)target.Presenter.Panel.Children[9];
                var raised = 0;

                // Make sure a RequestBringIntoView event is raised for item 9. It won't be handled
                // by the ScrollContentPresenter as the item is already visible, so we don't need
                // handledEventsToo: true. Issue #3934 failed here because item 0 was being scrolled
                // into view due to SelectionMode.AlwaysSelected.
                target.AddHandler(Control.RequestBringIntoViewEvent, (s, e) =>
                {
                    Assert.Same(item, e.TargetObject);
                    ++raised;
                });

                // Click item 9.
                _mouse.Click(item);

                Assert.Equal(1, raised);
            }
        }
Пример #15
0
        public async void LoadUsers()
        {
            mainGrid.Children.Clear();
            var scroll = new ScrollViewer();

            mainGrid.Children.Add(scroll);
            this.listBox              = new ListBox();
            scroll.Content            = listBox;
            listBox.DisplayMemberPath = "Name";
            try
            {
                var users = await UsersProcessor.GetAllUsers();

                foreach (var user in users)
                {
                    listBox.Items.Add(user);
                }
            }
            catch
            {
                MessageBox.Show("Error while loading users");
            }

            ContextMenu contextMenu = new ContextMenu();


            MenuItem item = new MenuItem();

            item.Header = "Rename";
            item.Click += MenuItemRename_Click;
            contextMenu.Items.Add(item);

            item        = new MenuItem();
            item.Header = "Delete";
            item.Click += MenuItemDelete_Click;
            contextMenu.Items.Add(item);

            scroll.ContextMenu = contextMenu;

            listBox.AddHandler(UIElement.MouseLeftButtonDownEvent,
                               new MouseButtonEventHandler(OnMouseLeftButtonDown), true);
            // listBox.AddHandler(UIElement.MouseRightButtonDownEvent, new MouseButtonEventHandler(OnMouseRightButtonDown), true);
        }
        private static void OnFirstVisibleItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ListBox listBox = d as ListBox;

            if (d == null)
            {
                throw new InvalidOperationException("The FirstVisibleItem attached property can only be applied to ListBox controls.");
            }

            // add scroll changed handler only if not yet added
            if (!_listBoxes.Contains(listBox))
            {
                _listBoxes.Add(listBox);
                listBox.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(ScrollChanged));
            }

            if (e.OldValue != e.NewValue)
            {
                listBox.SetFirstVisibleItem(e.NewValue);
            }
        }
Пример #17
0
        //constructor will call this function to build visual tree of main window
        private void buildUI()
        {
            //border's settings
            brdSurround = new Border()
            {
                BorderBrush = Brushes.Black, BorderThickness = new Thickness(2)
            };

            //Tittle bar's settings
            //rectangle
            rctTitleBar = new Rectangle()
            {
                Fill = Brushes.Black, MinHeight = 40
            };
            Grid.SetColumnSpan(rctTitleBar, 6);
            rctTitleBar.MouseLeftButtonDown += titleBar_MouseLeftButtonDown;

            lblExitX = new Label()
            {
                Content = "X", FontSize = 15, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Foreground = Brushes.White, Margin = new Thickness(5)
            };
            brdExit = new Border()
            {
                HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center
            };
            brdExit.MouseLeftButtonDown += ((s, e) => this.Close());
            Grid.SetColumn(brdExit, 5);
            //label
            lblTitle = new Label()
            {
                Content = "Floor Covering Simulator", VerticalContentAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, Foreground = Brushes.White, FontSize = 14
            };
            Grid.SetColumnSpan(lblTitle, 6);
            lblTitle.MouseLeftButtonDown += titleBar_MouseLeftButtonDown;

            //setting left separator's properties
            splitterLeft = new GridSplitter()
            {
                VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Center, Width = 2, Foreground = Brushes.Black, Background = Brushes.Black
            };
            Grid.SetRow(splitterLeft, 1);
            Grid.SetRowSpan(splitterLeft, 2);
            Grid.SetColumn(splitterLeft, 2);

            //setting right separator's properties
            splitterRight = new GridSplitter()
            {
                VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Center, Width = 2, Foreground = Brushes.Black, Background = Brushes.Black
            };
            Grid.SetRow(splitterRight, 1);
            Grid.SetColumn(splitterRight, 4);
            Grid.SetRowSpan(splitterRight, 2);

            //setting status bar's properties
            rctStatusBar = new Rectangle()
            {
                Fill = Brushes.Black, MinHeight = 20
            };
            Grid.SetRow(rctStatusBar, 3);
            Grid.SetColumnSpan(rctStatusBar, 6);

            //toolbar
            stkToolbar = new StackPanel()
            {
                HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top
            };
            Grid.SetRow(stkToolbar, 1);

            rctClear = new Rectangle()
            {
                MinHeight = 20, MinWidth = 20, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Fill = Brushes.Gray, Stroke = Brushes.White, Margin = new Thickness(5), ToolTip = "Clear"
            };
            rctClear.MouseLeftButtonDown += rctClear_MouseLeftButtonDown;

            rctWayPoint = new Rectangle()
            {
                MinHeight = 20, MinWidth = 20, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Fill = Brushes.LightGreen, Stroke = Brushes.White, Margin = new Thickness(5), ToolTip = "Way Point"
            };
            rctWayPoint.MouseLeftButtonDown += rctWayPoint_MouseLeftButtonDown;

            rctHurdle = new Rectangle()
            {
                MinHeight = 20, MinWidth = 20, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Fill = Brushes.Black, Stroke = Brushes.White, Margin = new Thickness(5), ToolTip = "Obstacle"
            };
            rctHurdle.MouseLeftButtonDown += rctHurdle_MouseLeftButtonDown;

            rctDestination = new Rectangle()
            {
                MinHeight = 20, MinWidth = 20, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Fill = Brushes.Orange, Stroke = Brushes.White, Margin = new Thickness(5), ToolTip = "Destination"
            };
            rctDestination.MouseLeftButtonDown += rctDestination_MouseLeftButtonDown;

            rctInitialPoint = new Rectangle()
            {
                MinHeight = 20, MinWidth = 20, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Fill = Brushes.Purple, Stroke = Brushes.White, Margin = new Thickness(5), ToolTip = "Source"
            };
            rctInitialPoint.MouseLeftButtonDown += rctInitialPoint_MouseLeftButtonDown;

            linEdge = new Line()
            {
                X1 = 0, Y1 = 0, X2 = 15, Y2 = 10, StrokeThickness = 2, Stroke = Brushes.Red, Margin = new Thickness(5), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center
            };
            linEdge.MouseLeftButtonDown += linEdge_MouseLeftButtonDown;

            //side panels
            txtleft = new TextBox()
            {
                MinWidth = 150, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Margin = new Thickness(5)
            };

            chb1        = new CheckBox();
            chb1.Margin = new Thickness(5);

            chb2        = new CheckBox();
            chb2.Margin = new Thickness(5);

            lstRight = new ListBox()
            {
                MinWidth = 150, MinHeight = 200, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Margin = new Thickness(5)
            };

            txt1 = new TextBox()
            {
                MinWidth = 150, MinHeight = 100, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Margin = new Thickness(5), AcceptsReturn = true
            };
            txt2 = new TextBox()
            {
                MinWidth = 150, MinHeight = 100, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Margin = new Thickness(5), AcceptsReturn = true
            };

            stkLeft = new StackPanel()
            {
                VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch
            };
            Grid.SetColumn(stkLeft, 1);
            Grid.SetRow(stkLeft, 1);

            stkLeftInternal = new StackPanel()
            {
                Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Left
            };

            //right side panel
            stkRight = new StackPanel()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch
            };
            Grid.SetRow(stkRight, 1);
            Grid.SetColumn(stkRight, 5);

            btnDimensions = new Button()
            {
                HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, MinHeight = 30, MinWidth = 100, Background = Brushes.Black, Content = "Get Floor Dimensions", Padding = new Thickness(5), Foreground = Brushes.White
            };
            btnDimensions.Click += ((s, e) => { initiateNewFloor(); });

            cmbDimensions = new ComboBox()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch, MinWidth = 100, Margin = new Thickness(5)
            };

            cvsGraph = new Canvas()
            {
                MinHeight = 200, MinWidth = 150, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Margin = new Thickness(5), Background = Brushes.White
            };

            txtDebug = new TextBox()
            {
                MinHeight = 200, MinWidth = 150, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Margin = new Thickness(5)
            };

            cmbDown = new ComboBox()
            {
                MinWidth = 150, HorizontalAlignment = HorizontalAlignment.Stretch, Margin = new Thickness(5)
            };

            btnFinalTree = new Button()
            {
                HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, MinHeight = 50, MinWidth = 100, Background = Brushes.Black, Content = "Calculate Path", Padding = new Thickness(5), Foreground = Brushes.White
            };
            btnFinalTree.Click += btnFinalTree_Click;

            //listBox hosting tiles of floor
            lstFloor = new ListBox()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch
            };
            lstFloor.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(lstBoxMouseDown), true);

            lstFloor.MouseLeftButtonDown += lstBoxMouseDown;
            lstFloor.MouseMove           += lstFloor_MouseMove;
            //setting style of floor

            lstFloor.ItemContainerStyle = (Style)this.FindResource("lstBoxStyle");

            lstFloor.ItemsPanel = (ItemsPanelTemplate)this.FindResource("lstBoxTemplate");;

            lstFloor.ItemsSource = floorBacklog;
            lstFloor.IsSynchronizedWithCurrentItem = true;

            brdFloorSurround = new Border()
            {
                BorderBrush = Brushes.Black, Margin = new Thickness(5), Padding = new Thickness(5)
            };
            Grid.SetRow(brdFloorSurround, 1);
            Grid.SetColumn(brdFloorSurround, 3);

            //building visual tree of the window
            brdExit.Child = lblExitX;

            stkToolbar.Children.Add(rctWayPoint);
            stkToolbar.Children.Add(rctHurdle);
            stkToolbar.Children.Add(rctClear);
            stkToolbar.Children.Add(rctInitialPoint);
            stkToolbar.Children.Add(rctDestination);
            stkToolbar.Children.Add(linEdge);

            stkLeftInternal.Children.Add(chb1);
            stkLeftInternal.Children.Add(chb2);
            stkLeft.Children.Add(txtleft);
            stkLeft.Children.Add(stkLeftInternal);
            stkLeft.Children.Add(lstRight);
            stkLeft.Children.Add(txt1);
            stkLeft.Children.Add(txt2);

            stkRight.Children.Add(cmbDimensions);
            stkRight.Children.Add(btnDimensions);
            stkRight.Children.Add(cvsGraph);
            stkRight.Children.Add(txtDebug);
            stkRight.Children.Add(btnFinalTree);
            stkRight.Children.Add(cmbDown);


            grdMain.Children.Add(rctTitleBar);
            grdMain.Children.Add(lblTitle);
            grdMain.Children.Add(brdExit);
            grdMain.Children.Add(splitterLeft);
            grdMain.Children.Add(splitterRight);
            grdMain.Children.Add(rctStatusBar);
            brdFloorSurround.Child = lstFloor;
            grdMain.Children.Add(brdFloorSurround);
            grdMain.Children.Add(stkLeft);
            grdMain.Children.Add(stkRight);
            brdSurround.Child = grdMain;
            grdMain.Children.Add(stkToolbar);

            //add everything to MainWindow
            this.Content = brdSurround;
        }
Пример #18
0
        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);
        }