/// <summary>
        /// Default constructor builds a ComboBox inline editor template.
        /// </summary>
        public CultureInfoEditor()
        {
            // not using databinding here because Silverlight does not support
            // the WPF CultureConverter that is used by Blend.
            FrameworkElementFactory comboBox = new FrameworkElementFactory(typeof(ComboBox));
            comboBox.AddHandler(
                ComboBox.LoadedEvent,
                new RoutedEventHandler(
                    (sender, e) =>
                    {
                        _owner = (ComboBox)sender;
                        _owner.SelectionChanged += EditorSelectionChanged;
                        INotifyPropertyChanged data = _owner.DataContext as INotifyPropertyChanged;
                        if (data != null)
                        {
                            data.PropertyChanged += DatacontextPropertyChanged;
                        }
                        _owner.DataContextChanged += CultureDatacontextChanged;
                    }));

            comboBox.SetValue(ComboBox.IsEditableProperty, false);
            comboBox.SetValue(ComboBox.DisplayMemberPathProperty, "DisplayName");
            comboBox.SetValue(ComboBox.ItemsSourceProperty, CultureInfo.GetCultures(CultureTypes.SpecificCultures));
            DataTemplate dt = new DataTemplate();
            dt.VisualTree = comboBox;

            InlineEditorTemplate = dt;
        }
예제 #2
0
 private static ItemsPanelTemplate GetDefaultPanel()
 {
     FrameworkElementFactory panel = new FrameworkElementFactory(typeof(WrapPanel));
     ItemsPanelTemplate template = new ItemsPanelTemplate(panel);
     template.Seal();
     return template;
 }
예제 #3
0
 /// <summary>
 /// Default constructor builds the default TextBox inline editor template.
 /// </summary>
 public EmptyEditor()
 {
     FrameworkElementFactory textBox = new FrameworkElementFactory(typeof(TextBox));
     textBox.SetValue(TextBox.IsReadOnlyProperty, true);
     DataTemplate dt = new DataTemplate();
     dt.VisualTree = textBox;
     InlineEditorTemplate = dt;
 }
예제 #4
0
        static TreeViewEx()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TreeViewEx), new FrameworkPropertyMetadata(typeof(TreeViewEx)));

            FrameworkElementFactory vPanel = new FrameworkElementFactory(typeof(VirtualizingTreePanel));
            vPanel.SetValue(VirtualizingTreePanel.IsItemsHostProperty, true);
            ItemsPanelTemplate vPanelTemplate = new ItemsPanelTemplate();
            vPanelTemplate.VisualTree = vPanel;
            ItemsPanelProperty.OverrideMetadata(typeof(TreeViewEx), new FrameworkPropertyMetadata(vPanelTemplate));

            KeyboardNavigation.DirectionalNavigationProperty.OverrideMetadata(typeof(TreeViewEx), new FrameworkPropertyMetadata(KeyboardNavigationMode.Contained));
            KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(TreeViewEx), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
        }
        /// <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;
        }
예제 #6
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;
		}
예제 #7
0
파일: DataGrid.cs 프로젝트: JianwenSun/cc
        /// <summary>
        ///     Instantiates global information.
        /// </summary>
        static DataGrid()
        {
            Type ownerType = typeof(DataGrid);

            DefaultStyleKeyProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(typeof(DataGrid)));
            FrameworkElementFactory dataGridRowPresenterFactory = new FrameworkElementFactory(typeof(DataGridRowsPresenter));
            dataGridRowPresenterFactory.SetValue(FrameworkElement.NameProperty, ItemsPanelPartName);
            ItemsPanelProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(new ItemsPanelTemplate(dataGridRowPresenterFactory)));
            VirtualizingPanel.IsVirtualizingProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(true, null, new CoerceValueCallback(OnCoerceIsVirtualizingProperty)));
            VirtualizingPanel.VirtualizationModeProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(VirtualizationMode.Recycling));
            ItemContainerStyleProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(null, new CoerceValueCallback(OnCoerceItemContainerStyle)));
            ItemContainerStyleSelectorProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(null, new CoerceValueCallback(OnCoerceItemContainerStyleSelector)));
            ItemsSourceProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata((PropertyChangedCallback)null, OnCoerceItemsSourceProperty));
            AlternationCountProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(0, null, new CoerceValueCallback(OnCoerceAlternationCount)));
            IsEnabledProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(new PropertyChangedCallback(OnIsEnabledChanged)));
            IsKeyboardFocusWithinPropertyKey.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(new PropertyChangedCallback(OnIsKeyboardFocusWithinChanged)));
            IsSynchronizedWithCurrentItemProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(null, new CoerceValueCallback(OnCoerceIsSynchronizedWithCurrentItem)));
            IsTabStopProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(false));
            KeyboardNavigation.DirectionalNavigationProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(KeyboardNavigationMode.Contained));
            KeyboardNavigation.ControlTabNavigationProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(KeyboardNavigationMode.Once));

            CommandManager.RegisterClassInputBinding(ownerType, new InputBinding(BeginEditCommand, new KeyGesture(Key.F2)));
            CommandManager.RegisterClassCommandBinding(ownerType, new CommandBinding(BeginEditCommand, new ExecutedRoutedEventHandler(OnExecutedBeginEdit), new CanExecuteRoutedEventHandler(OnCanExecuteBeginEdit)));

            CommandManager.RegisterClassCommandBinding(ownerType, new CommandBinding(CommitEditCommand, new ExecutedRoutedEventHandler(OnExecutedCommitEdit), new CanExecuteRoutedEventHandler(OnCanExecuteCommitEdit)));

            CommandManager.RegisterClassInputBinding(ownerType, new InputBinding(CancelEditCommand, new KeyGesture(Key.Escape)));
            CommandManager.RegisterClassCommandBinding(ownerType, new CommandBinding(CancelEditCommand, new ExecutedRoutedEventHandler(OnExecutedCancelEdit), new CanExecuteRoutedEventHandler(OnCanExecuteCancelEdit)));

            CommandManager.RegisterClassCommandBinding(ownerType, new CommandBinding(SelectAllCommand, new ExecutedRoutedEventHandler(OnExecutedSelectAll), new CanExecuteRoutedEventHandler(OnCanExecuteSelectAll)));

            CommandManager.RegisterClassCommandBinding(ownerType, new CommandBinding(DeleteCommand, new ExecutedRoutedEventHandler(OnExecutedDelete), new CanExecuteRoutedEventHandler(OnCanExecuteDelete)));

            // Default Clipboard handling
            CommandManager.RegisterClassCommandBinding(typeof(DataGrid), new CommandBinding(ApplicationCommands.Copy, new ExecutedRoutedEventHandler(OnExecutedCopy), new CanExecuteRoutedEventHandler(OnCanExecuteCopy)));

            EventManager.RegisterClassHandler(typeof(DataGrid), MouseUpEvent, new MouseButtonEventHandler(OnAnyMouseUpThunk), true);
        }
예제 #8
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            dataGrid.ItemsSource           = ProductsController.Instance.GetAllProducts();
            dataGrid.Columns[0].Visibility = System.Windows.Visibility.Hidden;
            dataGrid.Columns[5].Visibility = System.Windows.Visibility.Hidden;
            dataGrid.IsReadOnly            = true;

            var buttonColumn = new DataGridTemplateColumn();

            buttonColumn.Header = "Adauga la comanda";

            DataTemplate            buttonTemplate = new DataTemplate();
            FrameworkElementFactory buttonFactory  = new FrameworkElementFactory(typeof(Button));

            buttonTemplate.VisualTree = buttonFactory;
            buttonFactory.AddHandler(Button.ClickEvent, new RoutedEventHandler(button_click));


            buttonFactory.SetValue(ContentProperty, "Adauga");
            buttonColumn.CellTemplate = buttonTemplate;

            dataGrid.Columns.Add(buttonColumn);
        }
예제 #9
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            IsManipulationEnabled = true;
            _itemsControl         = GetTemplateChild("PART_ItemsControl") as ItemsControl;
            if (_itemsControl == null)
            {
                return;
            }

            _itemsControl.ApplyTemplate();

            var factoryPanel = new FrameworkElementFactory(typeof(ZoomableCanvas));

            factoryPanel.AddHandler(LoadedEvent, new RoutedEventHandler(ZoomableCanvasLoaded));
            _itemsControl.ItemsPanel = new ItemsPanelTemplate(factoryPanel);

            if (_spatialSource != null)
            {
                _itemsControl.ItemsSource = _spatialSource;
            }
        }
예제 #10
0
        private GridViewDataColumn AddPosition(string resourceKey, string member, string dataMember, GridViewLength width)
        {
            var fef         = new FrameworkElementFactory(typeof(TextBlock));
            var bindingText = new Binding(member);

            fef.SetBinding(TextBlock.TextProperty, bindingText);

            var template = new DataTemplate();

            template.VisualTree = fef;
            template.Seal();

            var column = new GridViewDataColumn
            {
                Header            = CommonResourceManager.Instance.GetResourceString(resourceKey),
                DataMemberBinding = new Binding(dataMember),
                Width             = width == 0 ? new GridViewLength(1, GridViewLengthUnitType.Star) : width,
                CellTemplate      = template,
                UniqueName        = member,
            };

            return(column);
        }
예제 #11
0
        public CustomSelectEditor()
        {
            this.InlineEditorTemplate = new DataTemplate();
            FrameworkElementFactory combo = new FrameworkElementFactory(typeof(ComboBox));

            Binding b = new Binding("Value");

            b.Mode      = BindingMode.TwoWay;
            b.Converter = new StateConverter();
            combo.SetValue(ComboBox.SelectedValueProperty, b);
            Binding items = new Binding("options");

            items.Source = this;
            combo.SetValue(ComboBox.ItemsSourceProperty, items);
            combo.SetValue(ComboBox.SelectedValuePathProperty, "ID");
            DataTemplate            itemTemplate = new DataTemplate();
            FrameworkElementFactory textBlock    = new FrameworkElementFactory(typeof(TextBlock));
            Binding text = new Binding();

            text.Converter          = new DataTableConverter(); textBlock.SetValue(TextBlock.TextProperty, text);
            itemTemplate.VisualTree = textBlock; combo.SetValue(ComboBox.ItemTemplateProperty, itemTemplate);
            this.InlineEditorTemplate.VisualTree = combo;
        }
예제 #12
0
        public ColorGridBox()
        {
            FrameworkElementFactory factoryUnigrid = new FrameworkElementFactory(typeof(UniformGrid));

            factoryUnigrid.SetValue(UniformGrid.ColumnsProperty, 8);
            ItemsPanel = new ItemsPanelTemplate(factoryUnigrid);

            foreach (string strColor in strColors)
            {
                Rectangle rect = new Rectangle();
                rect.Width  = 12;
                rect.Height = 12;
                rect.Margin = new Thickness(4);
                rect.Fill   = (Brush)typeof(Brushes).GetProperty(strColor).GetValue(null, null);
                Items.Add(rect);

                ToolTip tip = new ToolTip();
                tip.Content  = strColor;
                rect.ToolTip = tip;
            }

            SelectedValuePath = "Fill";
        }
예제 #13
0
        public IntDataGridColumn(string name)
        {
            KeyboardNavigation.SetControlTabNavigation(this, KeyboardNavigationMode.None);
            Binding bind = new Binding(name);

            bind.Mode                = BindingMode.TwoWay;
            bind.Converter           = new IntConverter();
            bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            //bind.ValidationRules.Add(new IntValidation());
            bind.NotifyOnValidationError = true;

            FrameworkElementFactory textFactory = new FrameworkElementFactory(typeof(TextBox));

            textFactory.SetBinding(TextBox.TextProperty, bind);
            DataTemplate textTemplate = new DataTemplate();

            textTemplate.VisualTree = textFactory;
            // here I have a problem, I try as much as I can
            //textTemplate.Seal();
            //Validation.AddErrorHandler(textTemplate.LoadContent(), ErrorIntValidation);
            ////
            CellTemplate = textTemplate;
        }
예제 #14
0
        internal FrameworkElementFactory CreateButtonFactory(string iconName, double rotate, Thickness margin)
        {
            var buttonFactory   = new FrameworkElementFactory(typeof(Button));
            var imageFactory    = new FrameworkElementFactory(typeof(Image));
            var transformGroup  = new TransformGroup();
            var rotateTransform = new RotateTransform(rotate);

            transformGroup.Children.Add(rotateTransform);
            imageFactory.SetValue(Image.SourceProperty, (DrawingImage)(new FrameworkElement()).FindResource(iconName));
            imageFactory.SetValue(FrameworkElement.MarginProperty, margin);
            imageFactory.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
            imageFactory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            imageFactory.SetValue(FrameworkElement.RenderTransformProperty, transformGroup);
            buttonFactory.AppendChild(imageFactory);
            buttonFactory.SetValue(Grid.ColumnProperty, 1);
            buttonFactory.SetValue(FrameworkElement.MarginProperty, new Thickness(0));
            buttonFactory.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
            buttonFactory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            buttonFactory.SetValue(Button.BackgroundProperty, Brushes.Transparent);
            buttonFactory.SetValue(Button.BorderThicknessProperty, new Thickness(0));
            buttonFactory.SetValue(FrameworkElement.HeightProperty, 22d);
            return(buttonFactory);
        }
예제 #15
0
        //private static readonly DataTemplate DefaultTemplate;

        static ComboBoxBackend()
        {
            var factory = new FrameworkElementFactory(typeof(WindowsSeparator));

            factory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);

            var sepTemplate = new ControlTemplate(typeof(ComboBoxItem));

            sepTemplate.VisualTree = factory;

            DataTrigger trigger = new DataTrigger();

            trigger.Binding = new Binding(".[1]")
            {
                Converter = new TypeToStringConverter()
            };
            trigger.Value = typeof(ItemSeparator).Name;
            trigger.Setters.Add(new Setter(Control.TemplateProperty, sepTemplate));
            trigger.Setters.Add(new Setter(UIElement.IsEnabledProperty, false));

            ContainerStyle = new Style(typeof(ComboBoxItem));
            ContainerStyle.Triggers.Add(trigger);
        }
예제 #16
0
        public DrawTaskTree(Grid grid, Project project)
        {
            treeView = new TreeView();
            HierarchicalDataTemplate hdt       = new HierarchicalDataTemplate();
            FrameworkElementFactory  textBlock = new FrameworkElementFactory(typeof(TextBlock));

            textBlock.SetBinding(TextBlock.TextProperty, new Binding("TaskName"));
            hdt.ItemsSource = new Binding("Children");
            drawCM          = new DrawContextMenu();
            textBlock.SetValue(TextBlock.ContextMenuProperty, drawCM.contextMenuForTasks);
            hdt.VisualTree        = textBlock;
            treeView.ItemTemplate = hdt;
            treeView.ItemsSource  = project.Root;

            Thickness margin = treeView.Margin;

            margin.Top      = 10;
            margin.Right    = 1000;
            margin.Bottom   = 10;
            treeView.Margin = margin;

            CreateTaskTree(grid);
        }
예제 #17
0
        public CustomComboBoxWindowStateEditor()
        {
            DataTemplate customTemplate = new DataTemplate();

            FrameworkElementFactory comboBox = new FrameworkElementFactory(typeof(ComboBox));
            //LanguageParser utilObj = new LanguageParser();

            var YesNoList = new List <string>();

            YesNoList.Add("Normal");
            YesNoList.Add("Maxmize");
            YesNoList.Add("Minimize");

            comboBox.SetValue(ComboBox.ItemsSourceProperty, YesNoList);

            Binding selectedItems = new Binding("Value");

            comboBox.SetValue(ComboBox.SelectedItemProperty, selectedItems);
            selectedItems.Mode = BindingMode.TwoWay;

            this.InlineEditorTemplate            = customTemplate;
            this.InlineEditorTemplate.VisualTree = comboBox;
        }
예제 #18
0
        public ArgumentCollectionEditor()
        {
            this.InlineEditorTemplate = new DataTemplate();

            FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));

            stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label));
            Binding labelBinding          = new Binding("Value");

            label.SetValue(Label.ContentProperty, labelBinding);
            label.SetValue(Label.MaxWidthProperty, 90.0);

            stack.AppendChild(label);

            FrameworkElementFactory editModeSwitch = new FrameworkElementFactory(typeof(EditModeSwitchButton));

            editModeSwitch.SetValue(EditModeSwitchButton.TargetEditModeProperty, PropertyContainerEditMode.Dialog);

            stack.AppendChild(editModeSwitch);

            InlineEditorTemplate.VisualTree = stack;
        }
예제 #19
0
파일: Tests.cs 프로젝트: radtek/Ocr
        private Style CreateScrollbarStyle()
        {
            /*Setter templateSetter = new Setter();
             * templateSetter.Property = ScrollBar.BackgroundProperty;
             * templateSetter.Value = Brushes.Black;
             *
             * Style style = new Style(typeof(ScrollBar));
             * style.Setters.Add(templateSetter);*/

            Style style = new Style(typeof(ScrollBar));

            SetProperty(style, Stylus.IsFlicksEnabledProperty, false);
            SetProperty(style, ScrollBar.ForegroundProperty, new SolidColorBrush(Color.FromArgb(0xFF, 0xAD, 0xAB, 0xAB)));
            SetProperty(style, ScrollBar.BackgroundProperty, Brushes.Transparent);
            SetProperty(style, ScrollBar.WidthProperty, 7);

            ControlTemplate ct    = new ControlTemplate(typeof(ScrollBar));
            var             image = new FrameworkElementFactory(typeof(ScrollBar));

            SetProperty(style, ScrollBar.TemplateProperty, ct);

            return(style);
        }
예제 #20
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var dataTemplate = new DataTemplate(typeof(Entry));

            var stackPanelFactory = new FrameworkElementFactory(typeof(Grid));

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

            text.SetValue(TextBlock.TextTrimmingProperty, TextTrimming.CharacterEllipsis);
            text.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            text.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);

            text.SetBinding(TextBlock.TextProperty,
                            new Binding {
                Path = new PropertyPath($"[{_column.Name}]"), Converter = new EntryKeyValuePairToValueConverter()
            });

            stackPanelFactory.AppendChild(text);

            dataTemplate.VisualTree = stackPanelFactory;

            return(dataTemplate);
        }
        static AsyncDataGridColumnHeadersPresenter()
        {
            Type forType = typeof(AsyncDataGridColumnHeadersPresenter);

            DefaultStyleKeyProperty.OverrideMetadata(
                forType, new FrameworkPropertyMetadata(forType));

            // Arrange the headers in reverse order, i.e. from right to left,
            // to make the left header's gripper overlay the right header.
            var panelFactory = new FrameworkElementFactory(
                typeof(AsyncDataGridColumnHeadersPanel));

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

            var panelTemplate = new ItemsPanelTemplate(panelFactory);

            panelTemplate.Seal();

            ItemsPanelProperty.OverrideMetadata(
                forType, new FrameworkPropertyMetadata(panelTemplate));
        }
예제 #22
0
        /// <summary>
        /// Creates a content control column that displays the specified resource according to the specified converter.
        /// </summary>
        /// <typeparam name="T">The converter type.</typeparam>
        /// <param name="header">The column header string.</param>
        /// <param name="bindingName">The binding name, i.e the column name within the table.</param>
        /// <param name="parameter">A parameter to pass to the converter, ex: the name of the resource to use.</param>
        /// <returns>The newly created column.</returns>
        public DataGridTemplateColumn CreateResource <T>(string header, string bindingName, object parameter) where T : IValueConverter, new()
        {
            DataGridTemplateColumn col = new DataGridTemplateColumn
            {
                Header = MakeTextBlockHeader(header),
            };

            FrameworkElementFactory factory = new FrameworkElementFactory(typeof(ContentControl));
            Binding binding = new Binding(bindingName)
            {
                Mode               = BindingMode.OneWay,
                Converter          = new T(),
                ConverterParameter = parameter
            };

            factory.SetValue(ContentControl.ContentProperty, binding);
            col.CellTemplate = new DataTemplate
            {
                VisualTree = factory
            };
            Add(col.SetSelectorName(header));
            return(col);
        }
예제 #23
0
        public static void AddButtonColumn(this DataGrid grid, string content, RoutedEventHandler handler)
        {
            var buttonTemplate = new FrameworkElementFactory(typeof(Button));

            buttonTemplate.SetValue(ContentControl.ContentProperty, content);
            buttonTemplate.SetBinding(UIElement.IsEnabledProperty, new Binding("Status"));

            buttonTemplate.AddHandler(
                ButtonBase.ClickEvent,
                new RoutedEventHandler(handler)
                );

            grid.Columns.Add(
                new DataGridTemplateColumn()
            {
                Header       = content,
                CellTemplate = new DataTemplate()
                {
                    VisualTree = buttonTemplate
                }
            }
                );
        }
예제 #24
0
        private void AttachLayoutModuleTemplateSelector()
        {
            FrameworkElementFactory factory = new FrameworkElementFactory(typeof(ContentControl));

            Binding viewModelBinding = new Binding
            {
                Mode = BindingMode.OneWay
            };

            factory.SetBinding(Binder.ViewModelProperty, viewModelBinding);

            factory.SetValue(Control.IsTabStopProperty, false);
            factory.SetValue(Control.HorizontalContentAlignmentProperty, HorizontalAlignment.Stretch);
            factory.SetValue(Control.VerticalContentAlignmentProperty, VerticalAlignment.Stretch);

            AssociatedObject.LayoutItemTemplateSelector = new LayoutModuleTemplateSelector()
            {
                LayoutModuleTemplate = new DataTemplate(typeof(ILayoutModule))
                {
                    VisualTree = factory,
                },
            };
        }
        /// <summary>
        /// Creates the font family control.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <returns>
        /// The control.
        /// </returns>
        protected FrameworkElement CreateFontFamilyControl(PropertyItem property)
        {
            var c = new ComboBox {
                ItemsSource = GetFontFamilies()
            };

            if (property.PreviewFonts)
            {
                var dt = new DataTemplate {
                    DataType = typeof(ComboBox)
                };
                var factory = new FrameworkElementFactory(typeof(TextBlock));
                factory.SetValue(TextBlock.FontSizeProperty, property.FontSize);
                factory.SetValue(TextBlock.FontWeightProperty, FontWeight.FromOpenTypeWeight(property.FontWeight));
                factory.SetBinding(TextBlock.TextProperty, new Binding());
                factory.SetBinding(TextBlock.FontFamilyProperty, new Binding());
                dt.VisualTree  = factory;
                c.ItemTemplate = dt;
            }

            c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
            return(c);
        }
예제 #26
0
    public MainWindow()
    {
        InitializeComponent();
        var textBlock = new FrameworkElementFactory(typeof(TextBlock));

        textBlock.SetBinding(TextBlock.TextProperty, new Binding("CategoryName"));
        var dataTemplate = new DataTemplate
        {
            VisualTree = textBlock
        };
        var categoryListBox = new ListBox
        {
            ItemTemplate = dataTemplate
        };

        BindingOperations.SetBinding(categoryListBox, ItemsControl.ItemsSourceProperty, new Binding
        {
            Source = categories
        });
        var grid = (Grid)this.Content;

        grid.Children.Add(categoryListBox);
    }
예제 #27
0
        private static DataGridTemplateColumn getDataGridTemplateColumn(object header, string bindingString)
        {
            DataGridTemplateColumn column = new DataGridTemplateColumn();

            column.Header = header;

            Binding binding = new Binding(bindingString);

            binding.Converter = polinomToXmlConverter;

            FrameworkElementFactory labelFactory = new FrameworkElementFactory(typeof(Label));

            labelFactory.SetBinding(Label.ContentProperty, binding);
            labelFactory.SetValue(Label.VerticalAlignmentProperty, VerticalAlignment.Bottom);
            labelFactory.SetValue(Label.HorizontalContentAlignmentProperty, HorizontalAlignment.Right);
            DataTemplate template = new DataTemplate();

            template.VisualTree = labelFactory;

            column.CellTemplate = template;

            return(column);
        }
예제 #28
0
        private void AddIndicator()
        {
            var separator = new Separator();

            separator.Visibility = Visibility.Hidden;
            separator.Margin     = new Thickness(0.0);
            separator.Width      = 2.0;

            var frameworkElementFactory = new FrameworkElementFactory(typeof(Border));

            frameworkElementFactory.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Black));//Color.FromUInt32(4278190208u)

            var controlTemplate = new ControlTemplate(typeof(Separator));

            controlTemplate.VisualTree = frameworkElementFactory;
            controlTemplate.Seal();

            separator.Template = controlTemplate;

            base.UIChildren.Add(separator);

            this._indicator = separator;
        }
 public static void dataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
 {
     if (!IsTypeOrNullableOfType(e.PropertyType, typeof(string)) &&
         !IsNullableOfValueType(e.PropertyType))
     {
         e.Cancel = true;
     }
     else if (IsTypeOrNullableOfType(e.PropertyType, typeof(DateTime)))
     {
         DataGridTemplateColumn col = new DataGridTemplateColumn();
         col.Header = e.Column.Header;
         FrameworkElementFactory datePickerFactoryElem = new FrameworkElementFactory(typeof(DatePicker));
         Binding dateBind = new Binding(e.PropertyName);
         dateBind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
         dateBind.Mode = BindingMode.TwoWay;
         datePickerFactoryElem.SetValue(DatePicker.SelectedDateProperty, dateBind);
         datePickerFactoryElem.SetValue(DatePicker.DisplayDateProperty, dateBind);
         DataTemplate cellTemplate = new DataTemplate();
         cellTemplate.VisualTree = datePickerFactoryElem;
         col.CellTemplate        = cellTemplate;
         e.Column = col;    //Set the new generated column
     }
 }
예제 #30
0
        private Style CreateStyle()
        {
            var controlTemplate = new ControlTemplate(typeof(TabItem));
            var grid            = new FrameworkElementFactory(typeof(Grid));

            var contentPresenter = new FrameworkElementFactory(typeof(ContentPresenter));

            contentPresenter.SetValue(NameProperty, "ContentSite");
            contentPresenter.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
            contentPresenter.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center);
            contentPresenter.SetValue(ContentPresenter.ContentSourceProperty, "Header");

            var selectedSetter2 = new Setter {
                Property = ZIndexProperty, Value = -500
            };

            var selectedTrigger = new Trigger {
                Property = TabItem.IsSelectedProperty, Value = true
            };

            selectedTrigger.Setters.Add(selectedSetter2);

            controlTemplate.Triggers.Add(selectedTrigger);

            grid.AppendChild(contentPresenter);
            controlTemplate.VisualTree = grid;

            var setter = new Setter {
                Property = Control.TemplateProperty, Value = controlTemplate
            };

            var style = new Style();

            style.Setters.Add(setter);

            return(style);
        }
예제 #31
0
        private FrameworkElementFactory CreateStackElement(ColumnData cd)
        {
            FrameworkElementFactory stackElement = null;

            switch (cd.Type.Name)
            {
            case "DataGridCheckBoxColumn":
                stackElement = this.CreateCheckBoxElement(cd);
                break;

            case "DataGridComboBoxColumn":
                stackElement = this.CreateComboBoxElement(cd);
                break;

            case "DataGridDateColumn":
                stackElement = this.CreateDatePickerElement(cd);
                break;

            case "DataGridTextColumn":
            case "DataGridNumericColumn":
                stackElement = this.CreateTextBoxElement(cd, false);
                break;

            case "DataGridTemplateColumn":
                stackElement = this.CreateDefaultElement(cd);
                break;

            case "DataGridDetailColumn":
                break;

            default:
                stackElement = this.CreateDefaultElement(cd);
                break;
            }

            return(stackElement);
        }
        public void CargarDatosDetails()
        {
            //Variables Auxiliares
            GridViewColumn          Columna;
            FrameworkElementFactory Txt;
            Assembly assembly;
            string   TipoDato;

            //Inicializo el DataTable
            View.Model.ListRecords = new DataTable("ListadoRegistros");

            //Asigno las columnas
            View.Model.ListRecords.Columns.Add("RowID", typeof(String));
            View.Model.ListRecords.Columns.Add("Producto", typeof(String));
            View.Model.ListRecords.Columns.Add("Serial", typeof(String));
            View.Model.ListRecords.Columns.Add("Mac", typeof(String));
            View.Model.ListRecords.Columns.Add("Estado", typeof(String));
            View.Model.ListRecords.Columns.Add("IdPallet", typeof(String));

            Columna        = new GridViewColumn();
            assembly       = Assembly.GetAssembly(Type.GetType("System.Windows.Controls.ComboBox, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"));
            TipoDato       = "System.Windows.Controls.ComboBox";
            Columna.Header = "Ubicaciones";
            Txt            = new FrameworkElementFactory(assembly.GetType(TipoDato));
            Txt.SetValue(ComboBox.ItemsSourceProperty, View.Model.ListadoPosiciones);
            Txt.SetValue(ComboBox.DisplayMemberPathProperty, "Name");
            //Txt.SetValue(ComboBox.SelectedValuePathProperty, "MetaMasterID");
            Txt.SetValue(ComboBox.SelectedValuePathProperty, "Code");
            Txt.SetBinding(ComboBox.SelectedValueProperty, new System.Windows.Data.Binding("Posicion"));
            Txt.SetValue(ComboBox.WidthProperty, (double)110);

            // add textbox template
            Columna.CellTemplate            = new DataTemplate();
            Columna.CellTemplate.VisualTree = Txt;
            View.ListadoEquipos.Columns.Add(Columna);                       //Creacion de la columna en el GridView
            View.Model.ListRecords.Columns.Add("Posicion", typeof(String)); //Creacion de la columna en el DataTable
        }
예제 #33
0
        private void InitSpline(List <YuMiPoHuaiModel> models, String str, MarkerType type)
        {
            SplineSeries spline = new SplineSeries();

            spline.XAxis = (CategoryAxisBase)dataChart.Axes[0];

            spline.YAxis = (NumericYAxis)dataChart.Axes[1];

            spline.ItemsSource     = models;
            spline.Visibility      = Visibility.Visible;
            spline.ValueMemberPath = str;
            spline.Thickness       = 3;
            spline.MarkerType      = type;

            if (YuMiPoHuaiPage.type == 3)
            {
                DataTemplate            template = new DataTemplate();
                FrameworkElementFactory fef      = new FrameworkElementFactory(typeof(Label));
                fef.SetBinding(Label.ContentProperty, new Binding()
                {
                    Path = new PropertyPath("Item." + str), Converter = new StringFormatConverter(), ConverterParameter = "0.00"
                });
                //fef.SetValue(Label.MarginProperty, new Thickness(0, 0, 0, 15));
                fef.SetValue(Label.ForegroundProperty, new SolidColorBrush(Colors.Green));
                fef.SetValue(Label.FontSizeProperty, Convert.ToDouble(14));
                fef.SetValue(Label.FontWeightProperty, FontWeight.FromOpenTypeWeight(700));
                template.VisualTree   = fef;
                spline.MarkerTemplate = template;
            }

            spline.ToolTip = InitToolTip(models, spline, str);
            //if (dataChart.Series.Count > 0)
            //{
            //    dataChart.Series.Clear();
            //}
            dataChart.Series.Add(spline);
        }
예제 #34
0
        private GridViewDataColumn GetMRatioColumn(string resourceKey, string member, GridViewLength width)
        {
            var fef = new FrameworkElementFactory(typeof(TextBlock));

            var bindingText = new Binding(member);
            bindingText.Converter = new MRatioToTextConverter();

            fef.SetBinding(TextBlock.TextProperty, bindingText);
            fef.SetValue(FrameworkElement.WidthProperty, 40.0);
            fef.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);

            var rect = new FrameworkElementFactory(typeof(Rectangle));
            rect.SetValue(FrameworkElement.WidthProperty, 20.0);

            var backgroundColorBinding = new Binding(member);
            backgroundColorBinding.Converter = new MRatioToColorConverter();
            rect.SetBinding(Shape.FillProperty, backgroundColorBinding);

            var sp = new FrameworkElementFactory(typeof(StackPanel));
            sp.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            sp.AppendChild(fef);
            sp.AppendChild(rect);

            var template = new DataTemplate { VisualTree = sp };
            template.Seal();

            var column = new GridViewDataColumn
            {
                Header = CommonResourceManager.Instance.GetResourceString(resourceKey),
                DataMemberBinding = new Binding(member),
                Width = width == 0 ? new GridViewLength(1, GridViewLengthUnitType.Star) : width,
                CellTemplate = template,
                UniqueName = member,
            };

            return column;
        }
예제 #35
0
        public GameWonOverlay()
        {
            //Create new image for sprite
            VictorySprite = new Image
            {
                Width  = 400,
                Height = 200,
                Name   = "VictorySprite"
            };
            //Set source of VictorySprite
            VictorySprite.Source = new BitmapImage(new Uri("pack://application:,,,/Images/victory-sprite.png"));

            //Create new button template for restart button
            ControlTemplate againButtonTemplate = new ControlTemplate(typeof(Button));
            var             againButtonImage    = new FrameworkElementFactory(typeof(Image));

            againButtonImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri("pack://application:,,,/Images/play-again-button.png", UriKind.RelativeOrAbsolute)));
            againButtonTemplate.VisualTree = againButtonImage;
            //Create new button to restart the game
            again = new Button
            {
                Width    = 125,
                Height   = 45,
                Name     = "againButton",
                Template = againButtonTemplate
            };
            //Subscribe the again button to the method it needs to run
            again.Click += Again_Click;

            //Set coardinate values
            VictorySpriteX = 201;
            VictorySpriteY = 140;
            againX         = 251;
            againY         = 300;
            menuX          = 424;
            menuY          = 300;
        }
        protected void InitializeGridAttribute()
        {
            grid = new BrowserGrid();
            var gridFactory     = new FrameworkElementFactory(typeof(Grid));
            var checkboxFactory = new FrameworkElementFactory(typeof(CheckBox));

            checkboxFactory.SetBinding(CheckBox.IsCheckedProperty, new Binding("IsSelected")
            {
                RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(DataGridRow), 1)
            });
            gridFactory.AppendChild(checkboxFactory);
            DataTemplate template = new DataTemplate();

            template.VisualTree    = gridFactory;
            grid.RowHeaderTemplate = template;
            var brushConverter = new System.Windows.Media.BrushConverter();

            System.Windows.Media.Brush bruch = (System.Windows.Media.Brush)brushConverter.ConvertFrom(System.Windows.Media.Brushes.LightBlue.Color.ToString());
            grid.AlternatingRowBackground         = bruch;
            grid.AlternatingRowBackground.Opacity = 0.3;

            for (int i = 0; i < getColumnAttributesCount(); i++)
            {
                DataGridColumn column = getColumnAttributesAt(i);
                column.Header = getColumnHeaderAttributesAt(i);
                column.Width  = getColumnWidthAttributeAt(i);

                if (column is DataGridBoundColumn)
                {
                    ((DataGridBoundColumn)column).Binding = getBindingAttributeAt(i);
                }
                grid.Columns.Add(column);
            }

            this.AttributeList.Content  = grid;
            this.grid.SelectionChanged += new SelectionChangedEventHandler(OnSelectionChange);
        }
        private static void OnMatrixChangedo(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var mextrix = e.NewValue as IMatrix;
            var dataGridCollectionControl = d as DataGridCollectionControl;

            if ((mextrix == null) || (dataGridCollectionControl == null))
            {
                return;
            }

            for (var i = 0; i < mextrix.ColumnCount; i++)
            {
                var col = new DataGridTemplateColumn();
                col.Header = "Sw_" + i;
                var propertyPathName = "Item[" + i + "]";
                col.SortMemberPath = propertyPathName;
                //col.Binding = new Binding(path:"Item["+i+"]");
                dataGridCollectionControl.MyDataGrid.Columns.Add(col);

                // First: create and add the data template to the parent control
                var dt = new DataTemplate(typeof(TextBox));
                col.CellTemplate = dt;

                // Second: create and add the text box to the data template
                var txtElement = new FrameworkElementFactory(typeof(TextBox));
                dt.VisualTree = txtElement;

                // Create binding
                var bind = new Binding();
                bind.Path = new PropertyPath(propertyPathName);
                bind.Mode = BindingMode.TwoWay;

                // Third: set the binding in the text box
                txtElement.SetBinding(TextBox.TextProperty, bind);
                txtElement.SetValue(FontSizeProperty, 18.0);
            }
        }
예제 #38
0
        // Create a FEF for a TextBlock, to be used in a default template
        internal static FrameworkElementFactory CreateTextBlockFactory()
        {
            FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));

            return text;
        }
예제 #39
0
        // ContentPresenter often has occasion to display text.  The TextBlock it uses
        // should get the values for various text-related properties (foreground, fonts,
        // decoration, trimming) from the governing ContentControl.  The following
        // two methods accomplish this - first for the case where the TextBlock appears
        // in a true template, then for the case where the TextBlock is created on
        // demand via BuildVisualTree.

        // Create a FEF for a AccessText, to be used in a default template
        internal static FrameworkElementFactory CreateAccessTextFactory()
        {
            FrameworkElementFactory text = new FrameworkElementFactory(typeof(AccessText));

            return text;
        }
예제 #40
0
 /// <summary>
 ///     ItemsPanelTemplate Constructor 
 /// </summary> 
 public ItemsPanelTemplate(FrameworkElementFactory root)
 { 
     VisualTree = root;
 }
        // Create the indicator for column re-ordering
        private void AddIndicator()
        {
            Separator indicator = new Separator();
            indicator.Visibility = Visibility.Hidden;

            // Indicator style:
            //
            // <Setter Property="Margin" Value="0" />
            // <Setter Property="Width" Value="2" />
            // <Setter Property="Template">
            //   <Setter.Value>
            //     <ControlTemplate TargetType="{x:Type Separator}">
            //        <Border Background="#FF000080"/>
            //     </ControlTemplate>
            //   </Setter.Value>
            // </Setter>

            indicator.Margin = new Thickness(0);
            indicator.Width = 2.0;

            FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
            border.SetValue(Border.BackgroundProperty, new SolidColorBrush(Color.FromUInt32(0xFF000080)));

            ControlTemplate template = new ControlTemplate(typeof(Separator));
            template.VisualTree = border;
            template.Seal();

            indicator.Template = template;

            InternalChildren.AddInternal(indicator);
            _indicator = indicator;
        }
예제 #42
0
 /// <summary>Adds a child factory to this factory.</summary>
 /// <param name="child">The <see cref="T:System.Windows.FrameworkElementFactory" /> object to add as a child.</param>
 public void AppendChild(FrameworkElementFactory child)
 {
     if (this.@sealed)
     {
         throw new InvalidOperationException("FrameworkElementFactory can't be changed after sealed");
     }
     if (child == null)
     {
         throw new ArgumentNullException("child");
     }
     if (child.parent != null)
     {
         throw new ArgumentException("FrameworkElementFactory already have Parent");
     }
     if (this.text != null)
     {
         throw new InvalidOperationException("FrameworkElementFactoryCannotAddText");
     }
     if (this.firstChild != null)
     {
         this.lastChild.nextSibling = child;
         this.lastChild = child;
     }
     else
     {
         this.firstChild = child;
         this.lastChild = child;
     }
     child.parent = this;
 }