Exemplo n.º 1
0
        public override Type SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            int controlIndex = 0;
            TypeConstraintAttribute dataAtt = ReflectionExt.FindAttribute <TypeConstraintAttribute>(attributes);
            Type baseType = dataAtt.BaseClass;

            Type[] children = baseType.GetAssignableTypes();

            Avalonia.Controls.Grid subGrid = (Avalonia.Controls.Grid)control.Children[controlIndex];
            ComboBox cbValue = (ComboBox)subGrid.Children[1];

            return(children[cbValue.SelectedIndex]);
        }
Exemplo n.º 2
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, Type member)
        {
            TypeConstraintAttribute dataAtt = ReflectionExt.FindAttribute <TypeConstraintAttribute>(attributes);
            Type baseType = dataAtt.BaseClass;

            Type[] children = baseType.GetAssignableTypes();

            Avalonia.Controls.Grid sharedRowPanel = getSharedRowPanel(2);

            TextBlock lblType = new TextBlock();

            lblType.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center;
            lblType.Text = name + ":";
            sharedRowPanel.Children.Add(lblType);
            sharedRowPanel.ColumnDefinitions[0].Width = new GridLength(30);
            lblType.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0);

            ComboBox cbValue = new ComboBox();

            cbValue.Margin = new Thickness(4, 0, 0, 0);
            sharedRowPanel.Children.Add(cbValue);
            cbValue.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1);

            List <string> items     = new List <string>();
            int           selection = 0;

            for (int ii = 0; ii < children.Length; ii++)
            {
                Type childType = children[ii];
                items.Add(childType.GetDisplayName());

                if (childType == (Type)member)
                {
                    selection = ii;
                }
            }

            var subject = new Subject <List <string> >();

            cbValue.Bind(ComboBox.ItemsProperty, subject);
            subject.OnNext(items);
            cbValue.SelectedIndex = selection;

            control.Children.Add(sharedRowPanel);
        }