Inheritance: Windows.UI.Xaml.Controls.UserControl
コード例 #1
0
        private void Render()
        {
            if (mainGrid == null)
            {
                return;
            }
            string[] lines = this.MetaData.Split("^".ToCharArray());

            StackPanel sp = spChildren; // new StackPanel();

            sp.Orientation = Orientation.Vertical;
            //sp.Transitions = new TransitionCollection();
            //sp.Transitions.Add(new EntranceThemeTransition());
            //mainGrid.Children.Add(sp);

            foreach (var line in lines)
            {
                string[] parts = line.Split("|".ToCharArray());

                UIElement   uie         = null;
                TextBlock   label       = null;
                Border      labelBorder = null;
                DPMandatory mandatory   = null;
                switch (parts[0].Trim())
                {
                case "slider":
                    uie = new Slider();
                    Slider te1 = (Slider)uie;
                    #region Slider
                    te1.Minimum             = double.Parse(parts[1]);
                    te1.Maximum             = double.Parse(parts[2]);
                    te1.Value               = double.Parse(parts[3]);
                    te1.Width               = double.Parse(parts[4]);
                    te1.Height              = double.Parse(parts[5]);
                    te1.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                    te1.ValueChanged       += (o, e) => {
                        Messenger.Default.Send(new DataEntryResponseMessage(e.NewValue.ToString())
                        {
                            Identifier = parts[6]
                        });
                    };
                    //te1.Foreground = new SolidColorBrush( Colors.Red);
                    //te1.Background = new SolidColorBrush(Colors.Gray);

                    label      = new TextBlock();
                    label.Text = parts[6];
                    label.HorizontalAlignment = StringToHorizontalAlignment(parts[8]);
                    label.VerticalAlignment   = StringToVerticalAlignment(parts[12]);
                    label.Foreground          = new SolidColorBrush(ColorConverter(parts[10]));
                    label.Margin   = new Thickness(10);
                    label.FontSize = double.Parse(parts[11]);

                    labelBorder            = new Border();
                    labelBorder.Width      = double.Parse(parts[7]);
                    labelBorder.Background = new SolidColorBrush(ColorConverter(parts[9]));
                    labelBorder.Child      = label;
                    labelBorder.Margin     = new Thickness(0, 0, 10, 0);

                    if (parts[13] == "1")
                    {
                        mandatory = new DPMandatory();
                    }
                    #endregion
                    break;

                case "textbox":
                    uie = new TextBox();
                    TextBox te2 = (TextBox)uie;
                    #region TextBox
                    te2.Width  = double.Parse(parts[1]);
                    te2.Height = double.Parse(parts[2]);
                    te2.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                    te2.BorderBrush         = new SolidColorBrush(Windows.UI.Colors.Gray);
                    te2.BorderThickness     = new Thickness(1);
                    te2.TextWrapping        = TextWrapping.Wrap;

                    label      = new TextBlock();
                    label.Text = parts[4];
                    label.HorizontalAlignment = StringToHorizontalAlignment(parts[6]);
                    label.VerticalAlignment   = StringToVerticalAlignment(parts[10]);
                    label.Foreground          = new SolidColorBrush(ColorConverter(parts[8]));
                    label.Margin   = new Thickness(10);
                    label.FontSize = double.Parse(parts[9]);

                    labelBorder            = new Border();
                    labelBorder.Width      = double.Parse(parts[5]);
                    labelBorder.Background = new SolidColorBrush(ColorConverter(parts[7]));
                    labelBorder.Child      = label;
                    labelBorder.Margin     = new Thickness(0, 0, 10, 0);

                    if (parts[11] == "1")
                    {
                        mandatory = new DPMandatory();
                    }
                    #endregion
                    break;

                case "listbox":
                    uie = new ListBox();
                    ListBox te3 = (ListBox)uie;
                    #region ListBox
                    te3.Width  = double.Parse(parts[1]);
                    te3.Height = double.Parse(parts[2]);
                    te3.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                    te3.BorderBrush         = new SolidColorBrush(Windows.UI.Colors.Gray);
                    te3.BorderThickness     = new Thickness(1);

                    label      = new TextBlock();
                    label.Text = parts[3];
                    label.HorizontalAlignment = StringToHorizontalAlignment(parts[5]);
                    label.VerticalAlignment   = StringToVerticalAlignment(parts[9]);
                    label.Foreground          = new SolidColorBrush(ColorConverter(parts[7]));
                    label.Margin   = new Thickness(10);
                    label.FontSize = double.Parse(parts[8]);

                    labelBorder            = new Border();
                    labelBorder.Width      = double.Parse(parts[4]);
                    labelBorder.Background = new SolidColorBrush(ColorConverter(parts[6]));
                    labelBorder.Child      = label;
                    labelBorder.Margin     = new Thickness(0, 0, 10, 0);

                    if (parts[10] == "1")
                    {
                        mandatory = new DPMandatory();
                    }
                    #endregion
                    break;

                case "combobox":
                    uie = new ComboBox();
                    ComboBox te4 = (ComboBox)uie;
                    #region ComboBox
                    te4.Width  = double.Parse(parts[1]);
                    te4.Height = double.Parse(parts[2]);
                    te4.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                    te4.BorderBrush         = new SolidColorBrush(Windows.UI.Colors.Gray);
                    te4.BorderThickness     = new Thickness(1);

                    label      = new TextBlock();
                    label.Text = parts[3];
                    label.HorizontalAlignment = StringToHorizontalAlignment(parts[5]);
                    label.VerticalAlignment   = StringToVerticalAlignment(parts[9]);
                    label.Foreground          = new SolidColorBrush(ColorConverter(parts[7]));
                    label.Margin   = new Thickness(10);
                    label.FontSize = double.Parse(parts[8]);


                    labelBorder            = new Border();
                    labelBorder.Width      = double.Parse(parts[4]);
                    labelBorder.Background = new SolidColorBrush(ColorConverter(parts[6]));
                    labelBorder.Child      = label;
                    labelBorder.Margin     = new Thickness(0, 0, 10, 0);

                    if (parts[10] == "1")
                    {
                        mandatory = new DPMandatory();
                    }
                    #endregion
                    break;

                case "checkbox":
                    uie = new CheckBox();
                    CheckBox te5 = (CheckBox)uie;
                    #region checkbox
                    te5.Width  = double.Parse(parts[1]);
                    te5.Height = double.Parse(parts[2]);
                    te5.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                    te5.IsChecked           = bool.Parse(parts[3]);
                    te5.Checked            += (o, e) =>
                    {
                        Messenger.Default.Send(new DataEntryResponseMessage("True")
                        {
                            Identifier = parts[4]
                        });
                    };
                    te5.Unchecked += (o, e) =>
                    {
                        Messenger.Default.Send(new DataEntryResponseMessage("False")
                        {
                            Identifier = parts[4]
                        });
                    };
                    //te1.Foreground = new SolidColorBrush( Colors.Red);
                    //te1.Background = new SolidColorBrush(Colors.Gray);

                    label      = new TextBlock();
                    label.Text = parts[4];
                    label.HorizontalAlignment = StringToHorizontalAlignment(parts[6]);
                    label.VerticalAlignment   = StringToVerticalAlignment(parts[11]);
                    label.Foreground          = new SolidColorBrush(ColorConverter(parts[8]));
                    label.Margin   = new Thickness(10);
                    label.FontSize = double.Parse(parts[9]);

                    labelBorder            = new Border();
                    labelBorder.Width      = double.Parse(parts[5]);
                    labelBorder.Background = new SolidColorBrush(ColorConverter(parts[7]));
                    labelBorder.Child      = label;
                    labelBorder.Margin     = new Thickness(0, 0, 10, 0);

                    if (parts[11] == "1")
                    {
                        mandatory = new DPMandatory();
                    }
                    #endregion
                    break;

                case "loadlist":
                    int       indexOfControl = int.Parse(parts[1]);
                    UIElement listControl    = _controls[indexOfControl];
                    #region LoadList
                    if (parts[2] == "reflection")
                    {
                        //SharpDX.Direct3D11.Comparison c2 = SharpDX.Direct3D11.Comparison.Always;

                        var t = Type.GetType(parts[3]);
                        //var lang = Activator.CreateInstance(t, new[] { "en-US" });
                        //var name = t.GetTypeInfo().GetDeclaredProperty("DisplayName").GetValue(lang);
                        LoadList(indexOfControl, t);
                    }
                    #endregion
                    break;

                default:     //unhandelled control
                    break;
                }


                if (uie != null)
                {
                    if (labelBorder != null)
                    {
                        //has a label
                        StackPanel spWithLabel = new StackPanel();
                        spWithLabel.Orientation = Orientation.Horizontal;
                        spWithLabel.Children.Add(labelBorder);
                        spWithLabel.Children.Add(uie);
                        spWithLabel.Margin = new Thickness(0, 10, 0, 0);

                        if (mandatory != null)
                        {
                            spWithLabel.Children.Add(mandatory);
                        }

                        sp.Children.Add(spWithLabel);
                    }
                    else
                    {
                        //no label

                        StackPanel spWithoutLabel = new StackPanel();
                        spWithoutLabel.Orientation = Orientation.Horizontal;
                        spWithoutLabel.Children.Add(uie);
                        spWithoutLabel.Margin = new Thickness(0, 10, 0, 0);
                        if (mandatory != null)
                        {
                            spWithoutLabel.Children.Add(mandatory);
                        }
                        sp.Children.Add(spWithoutLabel);
                    }

                    _controls.Add(uie);
                }

                if (mandatory != null)
                {
                    mandatory.Margin = new Thickness(10, 0, 0, 0);

                    _mandatoryControls.Add(mandatory);
                }
            }
            //sp.UpdateLayout();
        }
コード例 #2
0
ファイル: DataEntryPanel.cs プロジェクト: liquidboy/X
        private void Render()
        {
            if (mainGrid == null) return;
            string[] lines = this.MetaData.Split("^".ToCharArray());

            StackPanel sp = spChildren; // new StackPanel();            
            sp.Orientation = Orientation.Vertical;
            //sp.Transitions = new TransitionCollection();
            //sp.Transitions.Add(new EntranceThemeTransition());
            //mainGrid.Children.Add(sp);

            foreach (var line in lines)
            {
                string[] parts = line.Split("|".ToCharArray());

                UIElement uie = null;
                TextBlock label = null;
                Border labelBorder = null;
                DPMandatory mandatory = null;
                switch (parts[0].Trim())
                {
                    case "slider":
                        uie = new Slider();
                        Slider te1 = (Slider)uie;
                        #region Slider
                        te1.Minimum = double.Parse(parts[1]);
                        te1.Maximum = double.Parse(parts[2]);
                        te1.Value = double.Parse(parts[3]);
                        te1.Width = double.Parse(parts[4]);
                        te1.Height = double.Parse(parts[5]);
                        te1.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                        te1.ValueChanged += (o,e) => {
                            Messenger.Default.Send(new DataEntryResponseMessage(e.NewValue.ToString()) { Identifier = parts[6] });
                        };
                        //te1.Foreground = new SolidColorBrush( Colors.Red);
                        //te1.Background = new SolidColorBrush(Colors.Gray);

                        label = new TextBlock();
                        label.Text = parts[6];
                        label.HorizontalAlignment = StringToHorizontalAlignment(parts[8]);
                        label.VerticalAlignment = StringToVerticalAlignment(parts[12]);
                        label.Foreground = new SolidColorBrush(ColorConverter(parts[10]));
                        label.Margin = new Thickness(10);
                        label.FontSize = double.Parse(parts[11]);

                        labelBorder = new Border();
                        labelBorder.Width = double.Parse(parts[7]);
                        labelBorder.Background = new SolidColorBrush(ColorConverter(parts[9]));
                        labelBorder.Child = label;
                        labelBorder.Margin = new Thickness(0, 0, 10, 0);

                        if (parts[13] == "1") mandatory = new DPMandatory();
                        #endregion
                        break;
                    case "textbox": 
                        uie = new TextBox();
                        TextBox te2 = (TextBox)uie;
                        #region TextBox
                        te2.Width = double.Parse(parts[1]);
                        te2.Height = double.Parse(parts[2]);
                        te2.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                        te2.BorderBrush = new SolidColorBrush(Windows.UI.Colors.Gray);
                        te2.BorderThickness = new Thickness(1);
                        te2.TextWrapping = TextWrapping.Wrap;

                        label = new TextBlock();
                        label.Text = parts[4];
                        label.HorizontalAlignment = StringToHorizontalAlignment(parts[6]);
                        label.VerticalAlignment = StringToVerticalAlignment(parts[10]);
                        label.Foreground = new SolidColorBrush(ColorConverter(parts[8]));
                        label.Margin = new Thickness(10);
                        label.FontSize = double.Parse(parts[9]);

                        labelBorder = new Border();
                        labelBorder.Width = double.Parse(parts[5]);
                        labelBorder.Background = new SolidColorBrush(ColorConverter(parts[7]));
                        labelBorder.Child = label;
                        labelBorder.Margin = new Thickness(0, 0, 10, 0);

                        if (parts[11] == "1") mandatory = new DPMandatory();
                        #endregion
                        break;
                    case "listbox": 
                        uie = new ListBox();
                        ListBox te3 = (ListBox)uie;
                        #region ListBox
                        te3.Width = double.Parse(parts[1]);
                        te3.Height = double.Parse(parts[2]);
                        te3.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                        te3.BorderBrush = new SolidColorBrush(Windows.UI.Colors.Gray);
                        te3.BorderThickness = new Thickness(1);

                        label = new TextBlock();
                        label.Text = parts[3];
                        label.HorizontalAlignment = StringToHorizontalAlignment(parts[5]);
                        label.VerticalAlignment = StringToVerticalAlignment(parts[9]);
                        label.Foreground = new SolidColorBrush(ColorConverter(parts[7]));
                        label.Margin = new Thickness(10);
                        label.FontSize = double.Parse(parts[8]);

                        labelBorder = new Border();
                        labelBorder.Width = double.Parse(parts[4]);
                        labelBorder.Background = new SolidColorBrush(ColorConverter(parts[6]));
                        labelBorder.Child = label;
                        labelBorder.Margin = new Thickness(0, 0, 10, 0);

                        if (parts[10] == "1") mandatory = new DPMandatory();
                        #endregion
                        break;
                    case "combobox": 
                        uie = new ComboBox();
                        ComboBox te4 = (ComboBox)uie;
                        #region ComboBox
                        te4.Width = double.Parse(parts[1]);
                        te4.Height = double.Parse(parts[2]);
                        te4.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                        te4.BorderBrush = new SolidColorBrush(Windows.UI.Colors.Gray);
                        te4.BorderThickness = new Thickness(1);

                        label = new TextBlock();
                        label.Text = parts[3];
                        label.HorizontalAlignment = StringToHorizontalAlignment(parts[5]);
                        label.VerticalAlignment = StringToVerticalAlignment(parts[9]);
                        label.Foreground = new SolidColorBrush(ColorConverter(parts[7]));
                        label.Margin = new Thickness(10);
                        label.FontSize = double.Parse(parts[8]);


                        labelBorder = new Border();
                        labelBorder.Width = double.Parse(parts[4]);
                        labelBorder.Background = new SolidColorBrush(ColorConverter(parts[6]));
                        labelBorder.Child = label;
                        labelBorder.Margin = new Thickness(0, 0, 10, 0);

                        if (parts[10] == "1") mandatory = new DPMandatory();
                        #endregion
                        break;

                    case "checkbox":
                        uie = new CheckBox();
                        CheckBox te5 = (CheckBox)uie;
                        #region checkbox
                        te5.Width = double.Parse(parts[1]);
                        te5.Height = double.Parse(parts[2]);
                        te5.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                        te5.IsChecked = bool.Parse(parts[3]);
                        te5.Checked += (o, e) =>
                        {
                            Messenger.Default.Send(new DataEntryResponseMessage("True") { Identifier = parts[4] });
                        };
                        te5.Unchecked += (o, e) =>
                        {
                            Messenger.Default.Send(new DataEntryResponseMessage("False") { Identifier = parts[4] });
                        };
                        //te1.Foreground = new SolidColorBrush( Colors.Red);
                        //te1.Background = new SolidColorBrush(Colors.Gray);

                        label = new TextBlock();
                        label.Text = parts[4];
                        label.HorizontalAlignment = StringToHorizontalAlignment(parts[6]);
                        label.VerticalAlignment = StringToVerticalAlignment(parts[11]);
                        label.Foreground = new SolidColorBrush(ColorConverter(parts[8]));
                        label.Margin = new Thickness(10);
                        label.FontSize = double.Parse(parts[9]);

                        labelBorder = new Border();
                        labelBorder.Width = double.Parse(parts[5]);
                        labelBorder.Background = new SolidColorBrush(ColorConverter(parts[7]));
                        labelBorder.Child = label;
                        labelBorder.Margin = new Thickness(0, 0, 10, 0);

                        if (parts[11] == "1") mandatory = new DPMandatory();
                        #endregion
                        break;
                    case "loadlist":
                        int indexOfControl = int.Parse(parts[1]);
                        UIElement listControl = _controls[indexOfControl];
                        #region LoadList
                        if (parts[2] == "reflection")
                        {
                            
                            //SharpDX.Direct3D11.Comparison c2 = SharpDX.Direct3D11.Comparison.Always;
                            
                            var t = Type.GetType(parts[3]);
                            //var lang = Activator.CreateInstance(t, new[] { "en-US" });
                            //var name = t.GetTypeInfo().GetDeclaredProperty("DisplayName").GetValue(lang); 
                            LoadList(indexOfControl, t);
                        }
                        #endregion
                        break;
                    default: //unhandelled control
                        break;

                }


                if (uie != null)
                {
                    if (labelBorder != null) 
                    {
                        //has a label
                        StackPanel spWithLabel = new StackPanel();
                        spWithLabel.Orientation = Orientation.Horizontal;
                        spWithLabel.Children.Add(labelBorder);
                        spWithLabel.Children.Add(uie);
                        spWithLabel.Margin = new Thickness(0, 10, 0, 0);

                        if (mandatory != null) spWithLabel.Children.Add(mandatory);

                        sp.Children.Add(spWithLabel);
                    }
                    else
                    {
                        //no label
                        
                        StackPanel spWithoutLabel = new StackPanel();
                        spWithoutLabel.Orientation = Orientation.Horizontal;
                        spWithoutLabel.Children.Add(uie);
                        spWithoutLabel.Margin = new Thickness(0, 10, 0, 0);
                        if (mandatory != null) spWithoutLabel.Children.Add(mandatory);
                        sp.Children.Add(spWithoutLabel);
                    }

                    _controls.Add(uie);
                }

                if (mandatory != null)
                {
                    mandatory.Margin = new Thickness(10, 0, 0, 0);

                    _mandatoryControls.Add(mandatory);
                }
                

            }
            //sp.UpdateLayout();
            
        }