/// <summary>
        /// Create the template for the expanded item in the navigation drop-down.
        /// </summary>
        private DataTemplate CreateMenuItemExpandedTemplate()
        {
            DataTemplate            navMenuItemExpandedTemplate = new DataTemplate();
            FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));

            text.SetBinding(TextBlock.TextProperty, new Binding("Entity.Name"));
            text.SetValue(TextBlock.MarginProperty, new Thickness(2, 0, 0, 0));
            text.SetValue(TextBlock.FontWeightProperty, FontWeights.Bold);
            navMenuItemExpandedTemplate.VisualTree = text;

            return(navMenuItemExpandedTemplate);
        }
Example #2
0
        private void UpdateTemplate()
        {
            var factory = new FrameworkElementFactory(typeof(TextBlock));

            factory.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment);
            factory.SetBinding(TextBlock.TextProperty, this._binding);

            this.CellTemplate = new DataTemplate
            {
                VisualTree = factory
            };
        }
        /// <summary>
        /// Create the template for the items in the breadcrumb display.
        /// </summary>
        private DataTemplate CreateBreadcrumbItemTemplate()
        {
            DataTemplate            navBreadcrumbItemTemplate = new DataTemplate();
            FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));

            text.SetBinding(TextBlock.TextProperty, new Binding("Entity.Name"));
            text.SetValue(TextBlock.TextTrimmingProperty, TextTrimming.CharacterEllipsis);
            text.SetValue(TextBlock.VerticalAlignmentProperty, System.Windows.VerticalAlignment.Center);
            navBreadcrumbItemTemplate.VisualTree = text;

            return(navBreadcrumbItemTemplate);
        }
        static MainWindow()
        {
            MimeMessage m; // DEBUG

            var spFactory = new FrameworkElementFactory(typeof(StackPanel));

            spFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);

            var senderTbFactory = new FrameworkElementFactory(typeof(TextBlock));

            senderTbFactory.SetBinding(TextBlock.TextProperty, new Binding("From[0].Name"));
            spFactory.AppendChild(senderTbFactory);

            var sep1TbFactory = new FrameworkElementFactory(typeof(TextBlock));

            sep1TbFactory.SetValue(TextBlock.TextProperty, " -> ");
            spFactory.AppendChild(sep1TbFactory);

            var receiverTbFactory = new FrameworkElementFactory(typeof(TextBlock));

            receiverTbFactory.SetBinding(TextBlock.TextProperty, new Binding("To[0].Address"));
            spFactory.AppendChild(receiverTbFactory);

            var sep2TbFactory = new FrameworkElementFactory(typeof(TextBlock));

            sep2TbFactory.SetValue(TextBlock.TextProperty, " : ");
            spFactory.AppendChild(sep2TbFactory);

            var subjectTbFactory = new FrameworkElementFactory(typeof(TextBlock));

            subjectTbFactory.SetBinding(TextBlock.TextProperty, new Binding("Subject"));
            spFactory.AppendChild(subjectTbFactory);

            // TODO: установить триггер "прочитано-не прочитано"

            var sep3TbFactory = new FrameworkElementFactory(typeof(TextBlock));

            sep3TbFactory.SetValue(TextBlock.TextProperty, " (");
            spFactory.AppendChild(sep3TbFactory);

            var datetimeTbFactory = new FrameworkElementFactory(typeof(TextBlock));

            datetimeTbFactory.SetBinding(TextBlock.TextProperty, new Binding("Date"));
            spFactory.AppendChild(datetimeTbFactory);

            var sep4TbFactory = new FrameworkElementFactory(typeof(TextBlock));

            sep4TbFactory.SetValue(TextBlock.TextProperty, ")");
            spFactory.AppendChild(sep4TbFactory);

            letterDT            = new DataTemplate();
            letterDT.VisualTree = spFactory;
        }
Example #5
0
        private DataTemplate BuildDataTemplate(int index, FieldInfo fieldInfo)
        {
            DataTemplate            template  = new DataTemplate();
            FrameworkElementFactory textBlock = new FrameworkElementFactory(typeof(TextBlock));
            FrameworkElementFactory border    = new FrameworkElementFactory(typeof(Border));

            border.SetValue(Border.BorderThicknessProperty, new Thickness(2.0));
            border.AppendChild(textBlock);
            template.VisualTree = border;

            string sValuePath = CustomEntity.GetPropertyName(index);

            if (FieldInfo.HasFunctionField(fieldInfo))
            {
                sValuePath = CustomEntity.GetFuncValueName(index);
            }
            textBlock.SetBinding(TextBlock.TextProperty, new Binding(sValuePath));
            textBlock.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
            textBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Stretch);

            //Background color
            Binding bdColor = new Binding(CustomEntity.GetPropertyPath_ErrorBackground(index))
            {
                //RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.FindAncestor, AncestorType = typeof(DataRow) },
                Mode = BindingMode.OneWay
            };

            border.SetBinding(Border.BorderBrushProperty, bdColor);

            //Tooltip
            Binding bdTooltip = new Binding(CustomEntity.GetPropertyPath_ErrorTooltip(index))
            {
                //RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.FindAncestor, AncestorType = typeof(DataRow) },
                Mode = BindingMode.OneWay
            };

            textBlock.SetBinding(TextBlock.ToolTipProperty, bdTooltip);

            return(template);
        }
Example #6
0
        private void CreateContentTemplate()
        {
            var factory = new FrameworkElementFactory(typeof(Border));

            factory.SetValue(Border.SnapsToDevicePixelsProperty, true);
            factory.SetValue(Border.MarginProperty, new Thickness(0, 0, 0, 0));
            factory.SetBinding(Border.PaddingProperty, new Binding("Padding")
            {
                Source = this
            });
            factory.SetValue(Border.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
            factory.SetValue(Border.VerticalAlignmentProperty, VerticalAlignment.Stretch);
            factory.SetBinding(Border.BorderBrushProperty, new Binding("BorderBrush")
            {
                Source = this
            });
            factory.SetBinding(Border.BackgroundProperty, new Binding("ContentBackground")
            {
                Source = this
            });
            factory.SetBinding(Border.BorderThicknessProperty, new Binding("BorderThickness")
            {
                Source = this
            });

            var contentFactory = new FrameworkElementFactory(typeof(ContentPresenter));
            var binding        = new Binding()
            {
                Source = this,
                Path   = new PropertyPath("Content")
            };

            contentFactory.SetBinding(ContentPresenter.ContentProperty, binding);
            factory.AppendChild(contentFactory);

            var template = new DataTemplate();

            template.VisualTree  = factory;
            this.ContentTemplate = template;
        }
        public void Init(ServiceDisplayInfo service)
        {
            if (this.CurrentService == service)
            {
                return;
            }

            this.DataContext = this.CurrentService = service;

            _optionsHeaders = new List <string>();
            var options = service.Configuration.Extensions[OptionDefinitionCollection.ExtensionName] as OptionDefinitionCollection;

            if (options != null)
            {
                foreach (OptionDefinition option in options)
                {
                    if (option.IsPublic)
                    {
                        _optionsHeaders.Add(option.Name);
                    }
                }
            }

            var grid = this._ListView.View as GridView;

            for (int i = 0; i < _optionsHeaders.Count; i++)
            {
                string       option       = _optionsHeaders[i];
                DataTemplate cellTemplate = new DataTemplate();
                cellTemplate.VisualTree = new FrameworkElementFactory(typeof(Grid));
                var textbox = new FrameworkElementFactory(typeof(TextBox));
                textbox.SetBinding(TextBox.TextProperty, new Binding(String.Format("[{0}].Value", i)));
                cellTemplate.VisualTree.AppendChild(textbox);

                grid.Columns.Add(new GridViewColumn()
                {
                    Header       = option,
                    CellTemplate = cellTemplate,
                    Width        = 120
                });
            }
            ;

            this._instances = AppData.Load <ObservableCollection <List <BatchInstanceOption> > >(service.Name);
            if (this._instances == null)
            {
                this._instances = new ObservableCollection <List <BatchInstanceOption> >();
                this._instances.Add(NewInstance());
            }

            _ListView.ItemsSource = this._instances;
        }
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            DataTemplate dt = new DataTemplate();

            if (item != null && item is Context)
            {
                BaseInfoType model  = (item as Context).info;
                Window       window = Application.Current.MainWindow;
                if (model.GetInfoType().Equals(BaseInfoType.InfoType.LiteralText))
                {
                    //实例化标签控件
                    FrameworkElementFactory txtBox = new FrameworkElementFactory(typeof(TextBox));
                    txtBox.SetBinding(TextBox.TextProperty, new Binding()
                    {
                        Path = new PropertyPath("Content"),
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    txtBox.SetValue(TextBox.ForegroundProperty, Brushes.Black);
                    txtBox.SetValue(TextBox.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                    dt.VisualTree = txtBox;
                }
                else if (model.GetInfoType().Equals(BaseInfoType.InfoType.Picture))
                {
                    //实例化图像框控件
                    FrameworkElementFactory image = new FrameworkElementFactory(typeof(Image));
                    image.SetBinding(Image.SourceProperty, new Binding()
                    {
                        Path = new PropertyPath("Source"),
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    image.SetValue(Image.StretchProperty, Stretch.Uniform);
                    dt.VisualTree = image;
                }
                else
                {
                    //实例化文本控件
                    FrameworkElementFactory txtBox = new FrameworkElementFactory(typeof(TextBox));
                    txtBox.SetBinding(TextBox.TextProperty, new Binding()
                    {
                        Path = new PropertyPath("Content"),
                        Mode = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    txtBox.SetValue(TextBox.ForegroundProperty, Brushes.White);
                    txtBox.SetValue(TextBox.BackgroundProperty, new SolidColorBrush(Colors.Transparent));
                    dt.VisualTree = txtBox;
                }
            }
            return(dt);
        }
Example #9
0
        public override void AdaptTo(PropertyInfo property)
        {
            base.AdaptTo(property);
            if (property.PropertyType.IsEnum)
            {
                ItemsSource = Enum.GetValues(property.PropertyType);
            }
            else
            {
                AutoUIComboBoxAttribute cBA = property.GetCustomAttribute <AutoUIComboBoxAttribute>();

                if (cBA != null)
                {
                    if (string.IsNullOrWhiteSpace(cBA.ExtraItemsSource))
                    {
                        SetBinding(ItemsSourceProperty, cBA.ItemsSource);
                    }
                    else
                    {
                        // Bind to both the standard and extra item sources
                        ItemsSource = cBA.GetCombinedSourceCollection(this);
                    }
                }
                ItemTemplate = new DataTemplate();
                FrameworkElementFactory fEFactory = new FrameworkElementFactory(typeof(TextBlock));

                if (typeof(INamed).IsAssignableFrom(property.PropertyType))
                {
                    string textTemplate = "Name";
                    fEFactory.SetBinding(TextBlock.TextProperty, new Binding(textTemplate));
                }
                else
                {
                    if (typeof(Colour).IsAssignableFrom(property.PropertyType))
                    {
                        fEFactory = new FrameworkElementFactory(typeof(Border));

                        Binding binding = new Binding();
                        binding.Converter = new Converters.BrushConverter();
                        fEFactory.SetBinding(Border.BackgroundProperty, binding);
                        fEFactory.SetValue(Border.HeightProperty, 16d);
                        fEFactory.SetValue(Border.WidthProperty, 16d);
                    }
                    else
                    {
                        fEFactory.SetBinding(TextBlock.TextProperty, new Binding());
                    }
                }

                ItemTemplate.VisualTree = fEFactory;
            }
        }
Example #10
0
        //ListBoxを動的作成追加
        private void AddListBox()
        {
            var listBox = new ListBox();

            //ListBoxのItemsSourceのBindingはソースの指定もない空のBinding
            listBox.SetBinding(ListBox.ItemsSourceProperty, new Binding());

            //listboxの要素追加方向を横にする
            var stackPanel = new FrameworkElementFactory(typeof(StackPanel));

            stackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            var itemsPanel = new ItemsPanelTemplate()
            {
                VisualTree = stackPanel
            };

            listBox.ItemsPanel = itemsPanel;

            //ListBoxのアイテムテンプレート作成、設定
            //ItemTemplate作成、Bindingも設定する
            //縦積みのstackPanelにBorderとTextBlock
            //StackPanel(縦積み)
            //┣Border
            //┗TextBlock
            var border = new FrameworkElementFactory(typeof(Border));

            border.SetValue(WidthProperty, 20.0);
            border.SetValue(HeightProperty, 10.0);
            border.SetBinding(BackgroundProperty, new Binding(nameof(MyData.Brush)));

            var textBlock = new FrameworkElementFactory(typeof(TextBlock));

            textBlock.SetBinding(TextBlock.TextProperty, new Binding(nameof(MyData.ColorCode)));

            var panel = new FrameworkElementFactory(typeof(StackPanel));

            //panel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);//横積み
            panel.AppendChild(border);
            panel.AppendChild(textBlock);

            var dt = new DataTemplate();

            dt.VisualTree        = panel;
            listBox.ItemTemplate = dt;

            //追加(表示)
            MyStackPanel.Children.Add(listBox);


            //表示するデータ作成、設定
            listBox.DataContext = MakeMyDataList(MakeColors(5));
        }
Example #11
0
        private static DataTemplate CreateTextDataTemplate(string bindingPath)
        {
            var textBlockFactory = new FrameworkElementFactory(typeof(TextBlock));

            textBlockFactory.SetBinding(TextBlock.TextProperty, new Binding(bindingPath)
            {
                Converter = CellValueConverter.Instance
            });
            return(new DataTemplate(typeof(DependencyObject))
            {
                VisualTree = textBlockFactory
            });
        }
Example #12
0
    private DataTemplate GenerateCellTemplate(string eventType)
    {
        FrameworkElementFactory checkbox = new FrameworkElementFactory(typeof(CheckBox));

        checkbox.SetBinding(ToggleButton.IsCheckedProperty, new Binding("Value[" + eventType + "]")
        {
            Mode = BindingMode.TwoWay
        });
        return(new DataTemplate()
        {
            VisualTree = checkbox
        });
    }
Example #13
0
        private void InitializeResources()
        {
            var vmFactory = new FrameworkElementFactory(typeof(ViewModelViewHost));

            vmFactory.SetBinding(ViewModelViewHost.ViewModelProperty, new Binding("."));
            var vmTemplate = new DataTemplate(typeof(ReactiveObject))
            {
                VisualTree = vmFactory
            };

            vmTemplate.Seal();
            Resources.Add(new DataTemplateKey(typeof(ReactiveObject)), vmTemplate);
        }
Example #14
0
        public override FrameworkElementFactory GenerateField(IFactoryContext context, CheckBoxDescription fieldDescription)
        {
            FrameworkElementFactory root = new FrameworkElementFactory(typeof(CheckBox));

            root.SetValue(CheckBox.MarginProperty, new Thickness(2));
            root.SetValue(CheckBox.IsEnabledProperty, context.FormState != FormState.View);
            root.SetBinding(CheckBox.IsCheckedProperty, new Binding(fieldDescription.IsChecked)
            {
                Mode = BindingMode.TwoWay
            });

            return(root);
        }
        private DataTemplate GetDataColActionFlowControlTemplate(string Path)
        {
            DataTemplate            template = new DataTemplate();
            FrameworkElementFactory factory  = new FrameworkElementFactory(typeof(UCFlowControlAction));

            factory.SetBinding(UCDataColGrid.DataContextProperty, new Binding(Path));
            factory.SetValue(UCFlowControlAction.ActParentBusinessFlowProperty, mActParentBusinessFlow);
            factory.SetValue(UCFlowControlAction.ActParentActivityProperty, mActParentActivity);
            factory.SetValue(UCFlowControlAction.ActionProperty, mAct);
            factory.SetValue(UCFlowControlAction.RepositoryItemModeProperty, mEditMode);
            template.VisualTree = factory;
            return(template);
        }
        private DataTemplate CreateStringTemplate()
        {
            var textBoxFactory = new FrameworkElementFactory(typeof(TextBlock));
            var binding        = new Binding(nameof(DataContext))
            {
                Source = this
            };

            textBoxFactory.SetBinding(TextBlock.TextProperty, binding);
            return(new DataTemplate {
                VisualTree = textBoxFactory
            });
        }
Example #17
0
        } // ImageGridViewColumn

        // ----------------------------------------------------------------------
        protected ImageGridViewColumn(Stretch imageStretch)
        {
            FrameworkElementFactory imageElement = new FrameworkElementFactory(typeof(Image));

            // image source
            Binding imageSourceBinding = new Binding();

            imageSourceBinding.Converter = this;
            imageSourceBinding.Mode      = BindingMode.OneWay;
            imageElement.SetBinding(Image.SourceProperty, imageSourceBinding);

            // image stretching
            Binding imageStretchBinding = new Binding();

            imageStretchBinding.Source = imageStretch;
            imageElement.SetBinding(Image.StretchProperty, imageStretchBinding);

            DataTemplate template = new DataTemplate();

            template.VisualTree = imageElement;
            CellTemplate        = template;
        } // ImageGridViewColumn
Example #18
0
        //var gridViewColumn = new GridViewColumn() { Header = pi.Name, CellTemplate = GetCellTemplate(binding) };
        private static DataTemplate GetCellTemplate(Binding binding)
        {
            var template = new DataTemplate();
            var factory  = new FrameworkElementFactory(typeof(TextBlock));

            //factory.SetValue(RenderOptions.ClearTypeHintProperty, ClearTypeHint.Enabled);
            //factory.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Display);
            //factory.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Right);
            factory.SetBinding(TextBlock.TextProperty, binding);
            template.VisualTree = factory;

            return(template);
        }
        /// <summary>
        /// Default constructor builds the default TextBox inline editor template.
        /// </summary>
        public TextBoxEditor()
        {
            FrameworkElementFactory textBox = new FrameworkElementFactory(typeof(TextBox));
            Binding binding = new Binding();
            binding.Path = new PropertyPath("Value");
            binding.Mode = BindingMode.TwoWay;
            textBox.SetBinding(TextBox.TextProperty, binding);

            DataTemplate dt = new DataTemplate();
            dt.VisualTree = textBox;

            InlineEditorTemplate = dt;
        }
Example #20
0
        private static DataTemplate GetDataTemplate(string columnName)
        {
            DataTemplate            cell    = new DataTemplate(); // create a datatemplate
            FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBox));
            Binding binding = new Binding("[" + columnName + "]");

            binding.Mode = BindingMode.OneWay;
            factory.SetBinding(TextBox.TextProperty, binding);
            factory.SetValue(TextBox.IsReadOnlyProperty, true);
            factory.SetValue(TextBox.BorderBrushProperty, new SolidColorBrush()
            {
                Opacity = 1
            });
            factory.SetValue(TextBox.VerticalAlignmentProperty, VerticalAlignment.Stretch);
            factory.SetBinding(TextBox.ForegroundProperty, new Binding("Foreground"));
            factory.SetBinding(TextBox.BackgroundProperty, new Binding("Background"));
            factory.SetBinding(TextBox.FontFamilyProperty, new Binding("FontFamily"));
            factory.SetBinding(TextBox.FontSizeProperty, new Binding("FontSize"));
            cell.VisualTree = factory;

            return(cell);
        }
Example #21
0
        public DesignDataTemplate()
            : base(typeof(ExpandoObject))
        {
            var contentControl = new FrameworkElementFactory(typeof(ContentControl));

            contentControl.SetBinding(ContentControl.ContentProperty, new Binding()
            {
                Path = new PropertyPath(".")
            });
            contentControl.SetValue(ContentControl.ContentTemplateSelectorProperty, new DesignTemplateSelector());

            VisualTree = contentControl;
        }
Example #22
0
        /// <summary>
        /// Initialise le DataTemplate
        /// </summary>
        protected virtual void InitializeDataTemplate()
        {
            HierarchicalDataTemplate dataTemplate = new HierarchicalDataTemplate(typeof(Misp.Kernel.Domain.Measure));

            dataTemplate.ItemsSource = new Binding("childrenListChangeHandler.Items");

            FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBlock));

            factory.SetBinding(TextBlock.TextProperty, new Binding("name"));

            dataTemplate.VisualTree = factory;
            //this.tree.ItemTemplate = dataTemplate;
        }
Example #23
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (_uiElementTemplate == null)
            {
                var visualTree = new FrameworkElementFactory(typeof(ContentPresenter));
                visualTree.SetBinding(ContentPresenter.ContentProperty, new Binding());
                _uiElementTemplate = new DataTemplate {
                    VisualTree = visualTree
                };
            }

            return(item is UIElement ? _uiElementTemplate : DataTemplate);
        }
        /// <summary>
        /// Default constructor builds the default DataGridLengthEditor inline editor template.
        /// </summary>
        public DataGridLengthEditor()
        {
            FrameworkElementFactory dataGridLengthEditorGrid = new FrameworkElementFactory(typeof(DataGridLengthEditorGrid));
            Binding binding = new Binding("Value");

            binding.Mode = BindingMode.TwoWay;
            dataGridLengthEditorGrid.SetBinding(DataGridLengthEditorGrid.ValueProperty, binding);

            DataTemplate dataTemplate = new DataTemplate();

            dataTemplate.VisualTree   = dataGridLengthEditorGrid;
            this.InlineEditorTemplate = dataTemplate;
        }
Example #25
0
        // ##############################################################################################################################
        // Constructor
        // ##############################################################################################################################

        #region Constructor

        protected ImageGridViewColumn(Stretch imageStretch)
        {
            FrameworkElementFactory imageElement = new FrameworkElementFactory(typeof(Image));

            Binding imageSourceBinding = new Binding {
                Converter = this, Mode = BindingMode.OneWay
            };

            imageElement.SetBinding(Image.SourceProperty, imageSourceBinding);

            Binding imageStretchBinding = new Binding {
                Source = imageStretch
            };

            imageElement.SetBinding(Image.StretchProperty, imageStretchBinding);

            DataTemplate template = new DataTemplate {
                VisualTree = imageElement
            };

            CellTemplate = template;
        }
Example #26
0
        internal static FrameworkElementFactory CreateBoundCellRenderer(CellView view, string dataPath = ".")
        {
            TextCellView textView = view as TextCellView;

            if (textView != null)
            {
                FrameworkElementFactory factory = new FrameworkElementFactory(typeof(SWC.TextBlock));
                factory.SetValue(FrameworkElement.MarginProperty, CellMargins);

                if (textView.TextField != null)
                {
                    factory.SetBinding(SWC.TextBlock.TextProperty, new Binding(dataPath + "[" + textView.TextField.Index + "]"));
                }

                return(factory);
            }

            ImageCellView imageView = view as ImageCellView;

            if (imageView != null)
            {
                FrameworkElementFactory factory = new FrameworkElementFactory(typeof(ImageBox));
                factory.SetValue(FrameworkElement.MarginProperty, CellMargins);

                if (imageView.ImageField != null)
                {
                    var binding = new Binding(dataPath + "[" + imageView.ImageField.Index + "]")
                    {
                        Converter = new ImageToImageSourceConverter()
                    };

                    factory.SetBinding(ImageBox.ImageSourceProperty, binding);
                }

                return(factory);
            }

            CanvasCellView canvasView = view as CanvasCellView;

            if (canvasView != null)
            {
                FrameworkElementFactory factory = new FrameworkElementFactory(typeof(CanvasCellViewBackend));
                factory.SetValue(FrameworkElement.MarginProperty, CellMargins);

                factory.SetValue(CanvasCellViewBackend.CellViewProperty, view);

                return(factory);
            }

            throw new NotImplementedException();
        }
        public ListColorsEvenElegantlier()
        {
            Title = "List Colors Even Elegantlier";   // // свойство Title определяет заголовок окна
            // Создайте DataTemplate для элементов.
            DataTemplate template = new  DataTemplate(typeof(NamedBrush));
            // Создайте FrameworkElementFactory на основе StackPanel.
            FrameworkElementFactory factoryStack =
                new  FrameworkElementFactory(typeof(StackPanel));

            factoryStack.SetValue(StackPanel.OrientationProperty,
                                  Orientation.Horizontal);
            // Сделайте это корнем визуального дерева DataTemplate.
            template.VisualTree = factoryStack;
            // Создайте FrameworkElementFactory на основе Rectangle.
            FrameworkElementFactory factoryRectangle =
                new  FrameworkElementFactory(typeof(Rectangle));                   // Поддерживает создание шаблонов.

            factoryRectangle.SetValue(Rectangle.WidthProperty, 16.0);              // Задает значение свойства зависимостей.
            factoryRectangle.SetValue(Rectangle.HeightProperty, 16.0);             // Задает значение свойства зависимостей.
            factoryRectangle.SetValue(Rectangle.MarginProperty, new Thickness(2)); //Задает значение свойства зависимостей.
            factoryRectangle.SetValue(Rectangle.StrokeProperty,
                                      SystemColors.WindowTextBrush);               //Задает значение свойства зависимостей.
            factoryRectangle.SetBinding(Rectangle.FillProperty,
                                        new  Binding("Brush"));                    // Задает привязку данных для свойства.
            // Добавьте его в StackPanel.
            factoryStack.AppendChild(factoryRectangle);
            // Создайте FrameworkElementFactory на основе TextBlock.
            FrameworkElementFactory factoryTextBlock =
                new  FrameworkElementFactory(typeof(TextBlock)); // Поддерживает создание шаблонов.

            factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty,
                                      VerticalAlignment.Center); // Задает значение свойства зависимостей.
            factoryTextBlock.SetValue(TextBlock.TextProperty,
                                      new  Binding("Name"));     // Задает значение свойства зависимостей.
            // Добавьте его в StackPanel.
            factoryStack.AppendChild(factoryTextBlock);          // Добавляет дочернюю фабрику к данной фабрике.
            // Создайте ListBox в качестве содержимого окна.
            ListBox lstbox = new ListBox();                      // Содержит список элементов для выбора.

            lstbox.Width  = 150;                                 // Получение или установка ширины элемента.(Унаследовано от FrameworkElement)
            lstbox.Height = 150;                                 // Получает или задает предлагаемую высоту элемента.(Унаследовано от FrameworkElement)
            Content       = lstbox;                              // добавление
            // Установите свойство ItemTemplate в шаблон, созданный выше.
            lstbox.ItemTemplate = template;
            // Set the ItemsSource to the array of  NamedBrush objects.
            lstbox.ItemsSource = NamedBrush.All;
            // Установите ItemsSource в массив объектов NamedBrush.
            lstbox.SelectedValuePath = "Brush";                             // Возвращает или задает путь, используемый для получения SelectedValue из SelectedItem.(Унаследовано от Selector)
            lstbox.SetBinding(ListBox.SelectedValueProperty, "Background"); // Прикрепляет привязку к данному элементу на основе указанного имени исходного свойства в виде классификационного пути к источнику данных.(Унаследовано от FrameworkElement)
            lstbox.DataContext = this;                                      // Получает или задает контекст данных для элемента, участвующего в привязке данных.(Унаследовано от FrameworkElement)
        }
Example #28
0
        private static void OnMatrixSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ListViewExtension control = d as ListViewExtension;

            if (control.MainListView == null)
            {
                return;
            }

            DataMatrix dataMatrix = e.NewValue as DataMatrix;

            control.MainListView.ItemsSource = dataMatrix.Rows;
            var gridView = control.MainListView.View as System.Windows.Controls.GridView;
            int count    = 0;

            gridView.Columns.Clear();
            foreach (var col in dataMatrix.Columns)
            {
                var gridViewColumn = new GridViewColumn {
                    Header = "IM"
                };
                var dataTemplate = new DataTemplate();

                var gridFactory      = new FrameworkElementFactory(typeof(Grid));
                var textBlockFactory = new FrameworkElementFactory(typeof(TextBlock));

                dataTemplate.VisualTree = gridFactory;

                var newBinding = new Binding($"[{count}]");
                textBlockFactory.SetBinding(TextBlock.TextProperty, newBinding);
                textBlockFactory.SetValue(ForegroundProperty, new SolidColorBrush(Colors.Red));
                textBlockFactory.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Stretch);

                gridFactory.SetValue(WidthProperty, double.NaN);
                gridFactory.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
                gridFactory.AppendChild(textBlockFactory);

                var newHeader = new GridViewColumnHeader();
                newHeader.Content = col;
                newHeader.Width   = double.NaN;

                gridViewColumn.CellTemplate = dataTemplate;
                gridViewColumn.Header       = newHeader;
                gridViewColumn.Width        = double.NaN;
                gridViewColumn.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Stretch);

                gridView.Columns.Add(gridViewColumn);

                count++;
            }
        }
Example #29
0
        //private List<int> sumColumns = new List<int>();

        public void SetDataTable(DataTable _dt, string title, List <int> columnNumbers)
        {
            this.dt            = _dt.Copy();
            this.title         = title;
            this.columnNumbers = columnNumbers;
            _title.Text        = "▪ " + title;

            _gridview.Columns.Clear();
            foreach (DataColumn c in dt.Columns)
            {
                GridViewColumn gvc = new GridViewColumn();
                gvc.Header = c.ColumnName;
                gvc.Width  = (_listview.ActualWidth - 40) / dt.Columns.Count - 44;
                //gvc.DisplayMemberBinding = (new Binding(c.ColumnName));
                FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
                DataTemplate dataTemplate = new DataTemplate()
                {
                    VisualTree = text
                };
                gvc.CellTemplate = dataTemplate;
                gvc.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
                _gridview.Columns.Add(gvc);
            }
            if (BShowDetails)
            {
                GridViewColumn gvc_details = new GridViewColumn();
                gvc_details.Header = "详情";
                FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button));
                button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_details.SetValue(Button.WidthProperty, 40.0);
                button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click));
                button_details.SetBinding(Button.TagProperty, new Binding(dt.Columns[1].ColumnName));
                button_details.SetValue(Button.ContentProperty, ">>");
                button_details.SetValue(Button.ForegroundProperty, Brushes.Blue);
                button_details.SetValue(Button.FontSizeProperty, 14.0);
                button_details.SetBinding(Button.VisibilityProperty, new Binding(dt.Columns[0].ColumnName)
                {
                    Converter = new VisibleBtnConverter()
                });
                DataTemplate dataTemplate_details = new DataTemplate()
                {
                    VisualTree = button_details
                };
                gvc_details.CellTemplate = dataTemplate_details;
                _gridview.Columns.Add(gvc_details);
            }
            _listview.ItemsSource = dt.DefaultView;
        }
Example #30
0
 void UcTableView_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (dt == null)
     {
         return;
     }
     _gridview.Columns.Clear();
     foreach (DataColumn c in dt.Columns)
     {
         GridViewColumn gvc = new GridViewColumn();
         gvc.Header = c.ColumnName;
         gvc.Width  = (_listview.ActualWidth - 40) / dt.Columns.Count - 44;
         gvc.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
         //gvc.DisplayMemberBinding = (new Binding(c.ColumnName));
         FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
         text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
         text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
         text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
         DataTemplate dataTemplate = new DataTemplate()
         {
             VisualTree = text
         };
         gvc.CellTemplate = dataTemplate;
         _gridview.Columns.Add(gvc);
     }
     if (BShowDetails)
     {
         GridViewColumn gvc_details = new GridViewColumn();
         gvc_details.Header = "详情";
         FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button));
         button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
         button_details.SetValue(Button.WidthProperty, 40.0);
         button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click));
         button_details.SetBinding(Button.TagProperty, new Binding(dt.Columns[1].ColumnName));
         button_details.SetValue(Button.ContentProperty, ">>");
         button_details.SetValue(Button.ForegroundProperty, Brushes.Blue);
         button_details.SetValue(Button.FontSizeProperty, 14.0);
         button_details.SetBinding(Button.VisibilityProperty, new Binding(dt.Columns[0].ColumnName)
         {
             Converter = new VisibleBtnConverter()
         });
         DataTemplate dataTemplate_details = new DataTemplate()
         {
             VisualTree = button_details
         };
         gvc_details.CellTemplate = dataTemplate_details;
         _gridview.Columns.Add(gvc_details);
     }
     _listview.ItemsSource = null;
     _listview.ItemsSource = dt.DefaultView;
 }
Example #31
0
        public override GridViewColumn GetGridViewColumn(double actualWidth)
        {
            GridViewColumn v = new GridViewColumn();

            v.Width = actualWidth;

            ((INotifyPropertyChanged)v).PropertyChanged += GetHandler();

            Binding cptBinding = new Binding();

            cptBinding.Source = CTextLabel.Instance;
            cptBinding.Path   = new PropertyPath(cptKey);
            BindingOperations.SetBinding(v, GridViewColumn.HeaderProperty, cptBinding);

            Binding txtBinding = new Binding();

            txtBinding.Path = new PropertyPath(bdField);

            Binding colorBinding = new Binding();

            colorBinding.Path = new PropertyPath(BindingColorField);

            DataTemplate template = new DataTemplate();

            FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBlock));

            factory.SetValue(TextBlock.HorizontalAlignmentProperty, halgn);
            factory.SetBinding(TextBlock.TextProperty, txtBinding);
            if (!BindingColorField.Equals(""))
            {
                factory.SetBinding(TextBlock.ForegroundProperty, colorBinding);
            }
            template.VisualTree = factory;

            v.CellTemplate = template;

            return(v);
        }
Example #32
0
		public EditableTextBlock()
		{
			var textBox = new FrameworkElementFactory(typeof(TextBox));
			textBox.SetValue(Control.PaddingProperty, new Thickness(1)); // 1px for border
			textBox.AddHandler(FrameworkElement.LoadedEvent, new RoutedEventHandler(TextBox_Loaded));
			textBox.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown));
			textBox.AddHandler(UIElement.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
			textBox.SetBinding(TextBox.TextProperty, new Windows.UI.Xaml.Data.Binding("Text") { Source = this, Mode = BindingMode.TwoWay
#if TODO_XAML
				, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 
#endif
			});
			var editTemplate = new DataTemplate { VisualTree = textBox };

			var textBlock = new FrameworkElementFactory(typeof(TextBlock));
			textBlock.SetValue(FrameworkElement.MarginProperty, new Thickness(2));
			textBlock.AddHandler(UIElement.PointerPressedEvent, (s, e) => {
				PointerPoint pt;
				if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
					(pt = e.GetCurrentPoint(textBlock) != null) &&
#if TODO_XAML
					e.ClickCount >= 2 &&
#endif
					pt.Properties.IsLeftButtonPressed)
				{
					IsInEditMode = true;
					e.Handled = true;
				}

			});
			textBlock.SetBinding(TextBlock.TextProperty, new Windows.UI.Xaml.Data.Binding("Text") { Source = this });
			var viewTemplate = new DataTemplate { VisualTree = textBlock };

			var style = new Windows.UI.Xaml.Style(typeof(EditableTextBlock));
			var trigger = new Trigger { Property = IsInEditModeProperty, Value = true };
			trigger.Setters.Add(new Setter { Property = ContentTemplateProperty, Value = editTemplate });
			style.Triggers.Add(trigger);

			trigger = new Trigger { Property = IsInEditModeProperty, Value = false };
			trigger.Setters.Add(new Setter { Property = ContentTemplateProperty, Value = viewTemplate });
			style.Triggers.Add(trigger);
			Style = style;
		}