Beispiel #1
0
        public static void Main(string[] args)
        {
            WindowsHost windowsHost = ( WindowsHost )ConsoleApplication.LoadFromXaml("Examples.MainMenu.windows-host.xml", null);
            DataContext dataContext = new DataContext(  );
            Window      mainWindow  = ( Window )ConsoleApplication.LoadFromXaml(
                "Examples.MainMenu.main.xml", dataContext);

            windowsHost.Show(mainWindow);

            // Example of direct subscribing to Click event
            List <Control> menuItems = VisualTreeHelper.FindAllChilds(windowsHost.MainMenu, control => control is MenuItem);

            foreach (Control menuItem in menuItems)
            {
                MenuItem item = (( MenuItem )menuItem);
                if (item.Title == "Go")
                {
                    item.Click += (sender, eventArgs) => {
                        MessageBox.Show("", "", result => {
                            //
                        });
                    };
                }
            }
            ConsoleApplication.Instance.Run(windowsHost);
        }
Beispiel #2
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 #3
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 #4
0
        public static void Main(string[] args)
        {
            DataContext dataContext = new DataContext();
            WindowsHost windowsHost = (WindowsHost)ConsoleApplication.LoadFromXaml(
                "Examples.Commands.windows-host.xml", dataContext);
            Window mainWindow = (Window)ConsoleApplication.LoadFromXaml(
                "Examples.Commands.main.xml", dataContext);

            windowsHost.Show(mainWindow);
            ConsoleApplication.Instance.Run(windowsHost);
        }
Beispiel #5
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 static void Main(string[] args)
        {
            Context     context     = new Context();
            WindowsHost windowsHost = (WindowsHost)ConsoleApplication.LoadFromXaml(
                "Examples.TreeView.windows-host.xml", null);
            Window mainWindow = (Window)ConsoleApplication.LoadFromXaml(
                "Examples.TreeView.main.xml", context);

            windowsHost.Show(mainWindow);
            ConsoleFramework.Controls.TreeView tree = mainWindow.FindChildByName <ConsoleFramework.Controls.TreeView>("tree");
            // todo : придумать способ для того, чтобы обходиться без такого костыля
            context.Items = tree.Items;
            ConsoleApplication.Instance.Run(windowsHost);
        }
Beispiel #7
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 Main(string[] args)
        {
            WindowsHost windowsHost = ( WindowsHost )ConsoleApplication.LoadFromXaml("Examples.MainMenu.windows-host.xml", null);
            Window      mainWindow  = ( Window )ConsoleApplication.LoadFromXaml("Examples.MainMenu.main.xml", null);

            windowsHost.Show(mainWindow);
            CheckBox checkBox = mainWindow.FindChildByName <CheckBox>("checkbox");

            checkBox.OnClick += (sender, eventArgs) => {
                eventArgs.Handled = true;
            };
            List <Control> menuItems = VisualTreeHelper.FindAllChilds(windowsHost.MainMenu, control => control is MenuItem);

            foreach (Control menuItem in menuItems)
            {
                (( MenuItem )menuItem).Click += (sender, eventArgs) => {
                    MessageBox.Show("", "", result => {
                        //
                    });
                };
            }
            ConsoleApplication.Instance.Run(windowsHost);
        }
Beispiel #9
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 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);
            }
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            Logger.Disabled = false;

            ThreadPool.SetMaxThreads(3, 3);

            var cfg = ConverterConfigFactory.Get();

            ConverterConfigFactory.Save(cfg);

            dbconrtoller = new ArcController(cfg.ArcFileName)
            {
                AllowMessageLogging = cfg.AllowMessageLogging,
                SavePeriod          = cfg.SavePeriod,
                MaxDataLimit        = cfg.MaxLimit,
                Hyst = cfg.Hyst
            };
            //dbconrtoller.Start();

            var cts  = new CancellationTokenSource();
            var wCts = new CancellationTokenSource();

            var connnectionWfqydb = StreamSourceFactory.GetStreamSourceConfig(cfg.WFQYDBConnection).Get();

            var wFQYDBServer = new WFQYDBServer(
                connnectionWfqydb,
                new byte[] { 1, 0, 0, 0 },
                wCts.Token)
            {
                UpdatePeriod = new TimeSpan(0, 0, cfg.PeriodSec),
                CanA0        = cfg?.AllowedCommands.Contains <byte>(0xA0) ?? false,
                CanA1        = cfg?.AllowedCommands.Contains <byte>(0xA1) ?? false,
                CanA2        = cfg?.AllowedCommands.Contains <byte>(0xA2) ?? false,
                CanA3        = cfg?.AllowedCommands.Contains <byte>(0xA3) ?? false,
            };

            wFQYDBServer.PropertyChanged += WFQYDBServer_PropertyChanged;

            var modbusSvr = new ModbusSvr(
                cfg.ModbusSlaveTcpPort,
                cfg.ModbusSlaveRtuOverTcpPort,
                wFQYDBServer)
            {
                ArcController = dbconrtoller,
                //UpdatePeriod = new TimeSpan(cfg.PeriodSec * 10_000_000)
            };

            modbusSvr.Start();

            System.Threading.ThreadPool.GetMaxThreads(out int workerTh, out int completionTh);
            Logger.Info($"workerTh: {workerTh} completionTh: {completionTh}");

            if (args.Contains("TUI"))
            {
                Logger.Disabled = true;
                MainViewModel mvm = new MainViewModel();
                //mvm.ConnnectionWfqydb = connnectionWfqydb;
                mvm.WFQYDBServer = wFQYDBServer;
                mvm.ModbusSvr    = modbusSvr;
                Window window = (Window)ConsoleApplication
                                .LoadFromXaml("WfqydbModbusGateway.View.MainWin.xml", mvm);
                WindowsHost windowsHost = new WindowsHost {
                    Name = "temp"
                };
                windowsHost.Show(window);
                ConsoleApplication.Instance.Run(windowsHost);
            }
            else
            {
                int i = 0;

                while (!cts.Token.IsCancellationRequested)
                {
                    Thread.Sleep(200);
                    //if (wFQYDBServer.NeedToRestart)
                    //{
                    //    // restart services
                    //    Logger.Warn("Restarting services");
                    //    wCts.Cancel();
                    //    wCts = new CancellationTokenSource();
                    //    wFQYDBServer.PropertyChanged -= WFQYDBServer_PropertyChanged;
                    //    wFQYDBServer = new WFQYDBServer(connnectionWfqydb, new byte[] { 1, 0, 0, 0 }, cts.Token);
                    //    modbusSvr.WfqydbServer = wFQYDBServer;
                    //    GC.Collect();
                    //    wFQYDBServer.PropertyChanged += WFQYDBServer_PropertyChanged;
                    //}
                }
                wCts.Cancel();
                //Task.Delay(1000, cts.Token).Wait();
            }
            cts.Dispose();
            wCts.Dispose();
            dbconrtoller.Stop();
        }//Main
Beispiel #12
0
        public static void Main(string[] args)
        {
            Window window = (Window)ConsoleApplication.LoadFromXaml("TuiExperCF.Views.Win2.xml", context);

            window.KeyUp += WindowsHost_KeyUp;
            WindowsHost wh = new WindowsHost {
                Name = "temp"
            };

            wh.Show(window);
            ConsoleApplication.Instance.Run(wh);
            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,
                    Text = "{Binding Path=MyProperty}",
                };
                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();
                for (int i = 0; i < 30; i++)
                {
                    listBox.Items.Add(string.Format("Длинный элемент {0}", i));
                }
                //                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 = true;

                groupBox.Content = scrollViewer;

                ComboBox combo = new ComboBox();
                combo.ShownItemsCount = 10;
                for (int i = 0; i < 30; i++)
                {
                    combo.Items.Add(string.Format("Длинный элемент {0}", i));
                }
                //                groupBox.Content = combo;

                groupBox.HorizontalAlignment = HorizontalAlignment.Stretch;


                windowsHost.Show(new Window()
                {
                    X = 30,
                    Y = 6,
                    //MinHeight = 10,
                    //MinWidth = 10,
                    Height      = 14,
                    Name        = "LongTitleWindow",
                    Title       = "Очень длинное название окна",
                    Content     = groupBox,
                    DataContext = context,
                });
                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);

                windowsHost.KeyUp += WindowsHost_KeyUp;
            }
        }