Beispiel #1
0
        public static void Main( string[ ] args ) {
            WindowsHost windowsHost = new WindowsHost( );
            Window mainWindow = ( Window ) ConsoleApplication.LoadFromXaml( "Examples.AsyncUiUpdate.main.xml", null );
            windowsHost.Show( mainWindow );
            TextBlock textBlock = mainWindow.FindChildByName< TextBlock >( "text" );
            Thread thread = new Thread( ( ) => {
                int i = 1;
                for ( ;; ) {
                    ConsoleApplication.Instance.Post( new Action(( ) => {
                        textBlock.Text = i.ToString();
                    }) );
                    Thread.Sleep( 1000 );
					i++;
                }
            } );
            thread.IsBackground = true;
            thread.Start();

            mainWindow.FindChildByName< Button >( "btnMaximize" ).OnClick += ( sender, eventArgs ) => {
                ConsoleApplication.Instance.Maximize();
            };
            mainWindow.FindChildByName< Button >( "btnRestore" ).OnClick += ( sender, eventArgs ) => {
                ConsoleApplication.Instance.Restore();
            };

            ConsoleApplication.Instance.Run( windowsHost );
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //When choosing types for variables that are part of the DOM API,
            //You will want to use var when it's possible and dynamic when it's not.
            Console.WriteLine("Starting");

            WindowsHost windowsHost = new WindowsHost(  );
            Window window = new Window(  );
            Panel panel = new Panel( )
                {
                    Margin = new Thickness(1),
                    HorizontalAlignment = HorizontalAlignment.Stretch
                };
            panel.XChildren.Add( new TextBlock(  )
                {
                    Text = "Press the button",
                    Margin = new Thickness(0, 0, 0, 1),
                    HorizontalAlignment = HorizontalAlignment.Center
                });
            Button button = new Button( )
                {
                    Caption = "Button", HorizontalAlignment = HorizontalAlignment.Center
                };
            panel.XChildren.Add(button );
            button.OnClick += ( sender, eventArgs ) => {
                MessageBox.Show( "Info", "Button pressed !", result => {
                } );
            };
            window.Content = panel;
            window.Title = "Hello, Web !";
            windowsHost.Show( window );

            runWindows( windowsHost );
//            ConsoleApplication.Instance.Run( windowsHost );
        }
        private void openMenu( )
        {
            if (expanded)
            {
                return;
            }

            if (this.Type == MenuItemType.Submenu || Type == MenuItemType.RootSubmenu)
            {
                if (null == popup)
                {
                    popup = new Popup(this.Items, this.popupShadow, this.ActualWidth);
                    foreach (MenuItemBase itemBase in this.Items)
                    {
                        if (itemBase is MenuItem)
                        {
                            (( MenuItem )itemBase).ParentItem = this;
                        }
                    }
                    popup.AddHandler(Window.ClosedEvent, new EventHandler(onPopupClosed));
                }
                WindowsHost windowsHost = VisualTreeHelper.FindClosestParent <WindowsHost>(this);
                Point       point       = TranslatePoint(this, new Point(0, 0), windowsHost);
                popup.X = point.X;
                popup.Y = point.Y;
                windowsHost.ShowModal(popup, true);
                expanded = true;
            }
        }
Beispiel #4
0
 public static void Main( string[ ] args )
 {
     WindowsHost windowsHost = new WindowsHost( );
     Window mainWindow = ( Window ) ConsoleApplication.LoadFromXaml( "Examples.TabControl.main.xml", null );
     windowsHost.Show( mainWindow );
     ConsoleApplication.Instance.Run( windowsHost );
 }
Beispiel #5
0
        private void openPopup( )
        {
            if (opened)
            {
                throw new InvalidOperationException("Assertion failed.");
            }
            Window popup = new PopupWindow(Items, SelectedItemIndex ?? 0, shadow,
                                           ShownItemsCount != null ? ShownItemsCount.Value - 1 : ( int? )null);
            Point popupCoord = TranslatePoint(this, new Point(0, 0),
                                              VisualTreeHelper.FindClosestParent <WindowsHost>(this));

            popup.X     = popupCoord.X;
            popup.Y     = popupCoord.Y;
            popup.Width = shadow ? ActualWidth + 1 : ActualWidth;
            if (Items.Count != 0)
            {
                popup.Height = (ShownItemsCount != null ? ShownItemsCount.Value : Items.Count)
                               + (shadow ? 2 : 1); // 1 row for transparent "header"
            }
            else
            {
                popup.Height = shadow ? 3 : 2;
            }
            WindowsHost windowsHost = VisualTreeHelper.FindClosestParent <WindowsHost>(this);

            windowsHost.ShowModal(popup, true);
            opened = true;
            EventManager.AddHandler(popup, Window.ClosedEvent, new EventHandler(OnPopupClosed));
        }
Beispiel #6
0
 public static void Main( string[ ] args ) {
     WindowsHost windowsHost = new WindowsHost( );
     Window mainWindow = ( Window ) ConsoleApplication.LoadFromXaml( "Examples.CheckBoxes.main.xml", null );
     windowsHost.Show( mainWindow );
     CheckBox checkBox = mainWindow.FindChildByName<CheckBox>("checkbox");
     checkBox.OnClick += ( sender, eventArgs ) => {
         eventArgs.Handled = true;
     };
     ConsoleApplication.Instance.Run( windowsHost );
 }
        public void OpenMenu(WindowsHost windowsHost, Point point)
        {
            if (expanded)
            {
                return;
            }

            // Вешаем на WindowsHost обработчик события MenuItem.ClickEvent,
            // чтобы ловить момент выбора пункта меню в одном из модальных всплывающих окошек
            // Дело в том, что эти окошки не являются дочерними элементами контрола Menu,
            // а напрямую являются дочерними элементами WindowsHost (т.к. именно он создаёт
            // окна). И событие выбора пункта меню из всплывающего окошка может быть поймано
            // в WindowsHost, но не в Menu. А нам нужно повесить обработчик, который закроет
            // все показанные попапы.
            EventManager.AddHandler(windowsHost, MenuItem.ClickEvent,
                                    windowsHostClick = (sender, args) => {
                CloseAllSubmenus( );
                popup.Close(  );
            }, true);

            EventManager.AddHandler(windowsHost, MenuItem.Popup.ControlKeyPressedEvent,
                                    windowsHostControlKeyPressed = (sender, args) => {
                CloseAllSubmenus( );
                //
                //ConsoleApplication.Instance.FocusManager.SetFocusScope(this);
                if (args.wVirtualKeyCode == VirtualKeys.Right)
                {
                    ConsoleApplication.Instance.FocusManager.MoveFocusNext( );
                }
                else if (args.wVirtualKeyCode == VirtualKeys.Left)
                {
                    ConsoleApplication.Instance.FocusManager.MoveFocusPrev( );
                }
                MenuItem focusedItem = ( MenuItem )this.Items.SingleOrDefault(
                    item => item is MenuItem && item.HasFocus);
                focusedItem.Expand( );
            });

            if (null == popup)
            {
                popup = new MenuItem.Popup(this.Items, this.popupShadow, 0);
                popup.AddHandler(Window.ClosedEvent, new EventHandler(onPopupClosed));
            }
            popup.X = point.X;
            popup.Y = point.Y;
            windowsHost.ShowModal(popup, true);
            expanded         = true;
            this.windowsHost = windowsHost;
        }
Beispiel #8
0
        public static void Main( string[ ] args ) {
            WindowsHost windowsHost = new WindowsHost( );
            Window mainWindow = ( Window ) ConsoleApplication.LoadFromXaml( "Examples.RadioButtons.main.xml", null );
            windowsHost.Show( mainWindow );

            var button = mainWindow.FindChildByName<Button>("btn");
            button.OnClick += (sender, eventArgs) =>
            {
                var radioGroup = mainWindow.FindChildByName<RadioGroup>("radio");
                if (radioGroup.SelectedItem == null)
                    MessageBox.Show("", "Not selected yet", result => { });
                else
                    MessageBox.Show("", radioGroup.SelectedItem.Caption, result => { });
            };

            ConsoleApplication.Instance.Run( windowsHost );
        }
        public static void Show(string title, string text, MessageBoxClosedEventHandler onClosed)
        {
            Control rootControl = ConsoleApplication.Instance.RootControl;

            if (!(rootControl is WindowsHost))
            {
                throw new InvalidOperationException("Default windows host not found, create MessageBox manually");
            }
            WindowsHost windowsHost = ( WindowsHost )rootControl;
            MessageBox  messageBox  = new MessageBox(  );

            messageBox.Title = title;
            messageBox.Text  = text;
            messageBox.AddHandler(ClosedEvent, new EventHandler((sender, args) => {
                onClosed(MessageBoxResult.Button1);
            }));
            //messageBox.X =
            windowsHost.ShowModal(messageBox);
        }
Beispiel #10
0
        public void OpenMenu( WindowsHost windowsHost, Point point )
        {
            if ( expanded ) return;

            // Вешаем на WindowsHost обработчик события MenuItem.ClickEvent,
            // чтобы ловить момент выбора пункта меню в одном из модальных всплывающих окошек
            // Дело в том, что эти окошки не являются дочерними элементами контрола Menu,
            // а напрямую являются дочерними элементами WindowsHost (т.к. именно он создаёт
            // окна). И событие выбора пункта меню из всплывающего окошка может быть поймано
            // в WindowsHost, но не в Menu. А нам нужно повесить обработчик, который закроет
            // все показанные попапы.
            EventManager.AddHandler( windowsHost, MenuItem.ClickEvent,
                windowsHostClick = ( sender, args ) => {
                    CloseAllSubmenus( );
                    popup.Close(  );
                }, true );

            EventManager.AddHandler( windowsHost, MenuItem.Popup.ControlKeyPressedEvent,
                windowsHostControlKeyPressed = ( sender, args ) => {
                    CloseAllSubmenus( );
                    //
                    //ConsoleApplication.Instance.FocusManager.SetFocusScope(this);
                    if ( args.wVirtualKeyCode == VirtualKeys.Right )
                        ConsoleApplication.Instance.FocusManager.MoveFocusNext( );
                    else if ( args.wVirtualKeyCode == VirtualKeys.Left )
                        ConsoleApplication.Instance.FocusManager.MoveFocusPrev( );
                    MenuItem focusedItem = ( MenuItem ) this.Items.SingleOrDefault(
                        item => item is MenuItem && item.HasFocus );
                    focusedItem.Expand( );
                } );

            if ( null == popup ) {
                popup = new MenuItem.Popup( this.Items, this.popupShadow, 0 );
                popup.AddHandler( Window.ClosedEvent, new EventHandler( onPopupClosed ) );
            }
            popup.X = point.X;
            popup.Y = point.Y;
            windowsHost.ShowModal( popup, true );
            expanded = true;
            this.windowsHost = windowsHost;
        }
Beispiel #11
0
        private static void Main(string[] args) {
//            Control window = ConsoleApplication.LoadFromXaml( "ConsoleFramework.Layout.xml", null );
////            window.FindChildByName< TextBlock >( "text" ).MouseDown += ( sender, eventArgs ) => {
////                window.FindChildByName< TextBlock >( "text" ).Text = "F";
////                eventArgs.Handled = true;
////            };
////            window.MouseDown += ( sender, eventArgs ) => {
////                window.Width = window.ActualWidth + 3;
////                window.Invalidate(  );
////            };
//            ConsoleApplication.Instance.Run( window );
//            return;

            var assembly = Assembly.GetExecutingAssembly();
            var resourceName = "Examples.GridTest.xml";
            Window createdFromXaml;
            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            using (StreamReader reader = new StreamReader(stream))
            {
                string result = reader.ReadToEnd();
                MyDataContext dataContext = new MyDataContext( );
                dataContext.Str = "Введите заголовок";
                createdFromXaml = XamlParser.CreateFromXaml<Window>(result, dataContext, new List<string>()
                    {
                        "clr-namespace:Xaml;assembly=Xaml",
                        "clr-namespace:ConsoleFramework.Xaml;assembly=ConsoleFramework",
                        "clr-namespace:ConsoleFramework.Controls;assembly=ConsoleFramework",
                    });
            }
//            ConsoleApplication.Instance.Run(createdFromXaml);
//            return;

            using (ConsoleApplication application = ConsoleApplication.Instance) {
                Panel panel = new Panel();
                panel.Name = "panel1";
                panel.HorizontalAlignment =  HorizontalAlignment.Center;
                panel.VerticalAlignment = VerticalAlignment.Stretch;
                panel.XChildren.Add(new TextBlock() {
                    Name = "label1",
                    Text = "Label1",
                    Margin = new Thickness(1,2,1,0)
                    //,Visibility = Visibility.Collapsed
                });
                panel.XChildren.Add(new TextBlock() {
                    Name = "label2",
                    Text = "Label2_____",
                    HorizontalAlignment = HorizontalAlignment.Right
                });
                TextBox textBox = new TextBox() {
                    MaxWidth = 10,
                    Margin = new Thickness(1),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Size = 15
                };
                Button button = new Button() {
                    Name = "button1",
                    Caption = "Button!",
                    Margin = new Thickness(1),
                    HorizontalAlignment = HorizontalAlignment.Center
                };
                button.OnClick += (sender, eventArgs) => {
                    Debug.WriteLine("Click");
                    MessageBox.Show( "Окно сообщения", "Внимание ! Тестовое сообщение", delegate( MessageBoxResult result ) {  } );
                    Control label = panel.FindDirectChildByName("label1");
                    if (label.Visibility == Visibility.Visible) {
                        label.Visibility = Visibility.Collapsed;
                    } else if (label.Visibility == Visibility.Collapsed) {
                        label.Visibility = Visibility.Hidden;
                    } else {
                        label.Visibility = Visibility.Visible;
                    }
                    label.Invalidate();
                };
                ComboBox comboBox = new ComboBox(  )
                    {
//                        Width = 14
//HorizontalAlignment = HorizontalAlignment.Stretch
                    };
                comboBox.Items.Add( "Сделать одно" );
                comboBox.Items.Add("Сделать второе");
                comboBox.Items.Add("Ничего не делать");
                ListBox listbox = new ListBox(  );
                listbox.Items.Add( "First item" );
                listbox.Items.Add( "second item1!!!!!!1fff" );
                listbox.HorizontalAlignment = HorizontalAlignment.Stretch;
                //listbox.Width = 10;

                panel.XChildren.Add(comboBox);
                panel.XChildren.Add(button);
                panel.XChildren.Add(textBox);
                panel.XChildren.Add(listbox);
                
                //application.Run(panel);
                WindowsHost windowsHost = new WindowsHost()
                                              {
                                                  Name = "WindowsHost"
                                              };
                Window window1 = new Window {
                    X = 5,
                    Y = 4,
                    //MinHeight = 100,
                    //MaxWidth = 30,
                    //Width = 10,
                    Height = 20,
                    Name = "Window1",
                    Title = "Window1",
                    Content = panel
                };
                GroupBox groupBox = new GroupBox(  );
                groupBox.Title = "Группа";
                ScrollViewer scrollViewer = new ScrollViewer(  );
                ListBox listBox = new ListBox(  );
                listBox.Items.Add( "Длинный элемент" );
                listBox.Items.Add("Длинный элемент 2");
                listBox.Items.Add("Длинный элемент 3");
                listBox.Items.Add("Длинный элемент 4");
                listBox.Items.Add("Длинный элемент 5");
                listBox.Items.Add("Длинный элемент 6");
                listBox.Items.Add("Длинный элемент 700");
                listBox.HorizontalAlignment = HorizontalAlignment.Stretch;
                listBox.VerticalAlignment = VerticalAlignment.Stretch;
                scrollViewer.Content = listBox;
//                scrollViewer.HorizontalAlignment = HorizontalAlignment.Stretch;
                scrollViewer.VerticalAlignment = VerticalAlignment.Stretch;
                scrollViewer.HorizontalScrollEnabled = false;

                groupBox.Content = scrollViewer;
                groupBox.HorizontalAlignment = HorizontalAlignment.Stretch;

                windowsHost.Show(new Window() {
                    X = 30,
                    Y = 6,
                    //MinHeight = 10,
                    //MinWidth = 10,
                    Name = "LongTitleWindow",
                    Title = "Очень длинное название окна",
                    Content = groupBox
                });
                windowsHost.Show(window1);
                windowsHost.Show(createdFromXaml);
                //textBox.SetFocus(); todo : научиться задавать фокусный элемент до добавления в визуальное дерево
                //application.TerminalSizeChanged += ( sender, eventArgs ) => {
                //    application.CanvasSize = new Size(eventArgs.Width, eventArgs.Height);
                //   application.RootElementRect = new Rect(new Size(eventArgs.Width, eventArgs.Height));
               // };
				//windowsHost.Width = 80;
				//windowsHost.Height = 20;
				application.Run(windowsHost);//, new Size(80, 30), Rect.Empty);
            }
        }