public MainWindowViewModel()
        {
            SampleData.Seed();

            // create accent color menu items for the demo
            this.AccentColors = ThemeManager.Accents
                                            .Select(a => new AccentColorMenuData() { Name = a.Name, ColorBrush = a.Resources["AccentColorBrush"] as Brush })
                                            .ToList();

            // create metro theme color menu items for the demo
            this.AppThemes = ThemeManager.AppThemes
                                           .Select(a => new AppThemeMenuData() { Name = a.Name, BorderColorBrush = a.Resources["BlackColorBrush"] as Brush, ColorBrush = a.Resources["WhiteColorBrush"] as Brush })
                                           .ToList();
            

            Albums = SampleData.Albums;
            Artists = SampleData.Artists;

            FlipViewTemplateSelector = new RandomDataTemplateSelector();

            FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(Image));
            spFactory.SetBinding(Image.SourceProperty, new System.Windows.Data.Binding("."));
            spFactory.SetValue(Image.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
            spFactory.SetValue(Image.StretchProperty, Stretch.Fill);
            FlipViewTemplateSelector.TemplateOne = new DataTemplate()
            {
                VisualTree = spFactory
            };
            FlipViewImages = new string[] { "http://trinities.org/blog/wp-content/uploads/red-ball.jpg", "http://savingwithsisters.files.wordpress.com/2012/05/ball.gif" };

            RaisePropertyChanged("FlipViewTemplateSelector");


            BrushResources = FindBrushResources();
        }
        public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            var datatemplate = new DataTemplate();
            if (item == null)
                return datatemplate;
            if (_edit)
            {
                datatemplate.VisualTree = new FrameworkElementFactory(typeof(StackPanel));
                var converter = new EnumValueConverter(item,property);
                foreach (object value in Enum.GetValues(enumType))
                {
                    var cbox = new FrameworkElementFactory(typeof(CheckBox));
                    cbox.SetValue(CheckBox.ContentProperty, value.ToString());
                    Delegate add = (RoutedEventHandler)delegate(object obj, RoutedEventArgs e) { };
                    var b = new Binding(property);
                    b.Converter = converter;
                    b.ConverterParameter = value;
                    b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                    cbox.SetValue(CheckBox.IsCheckedProperty, b);
                    cbox.AddHandler(CheckBox.CheckedEvent, add);
                    cbox.AddHandler(CheckBox.UncheckedEvent, add);
                    datatemplate.VisualTree.AppendChild(cbox);
                }
            }
            else
            {
                datatemplate.VisualTree = new FrameworkElementFactory(typeof(Label));
                datatemplate.VisualTree.SetValue(Label.ContentProperty, new Binding(property));
            }

            return datatemplate;
        }
        private void ShowResourcesGained_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            RollDiceAction rollDice = e.NewValue as RollDiceAction;
            Dictionary<GamePlayer, ResourceList> result = rollDice.PlayersResources;

            basePanel.Children.Clear();

            foreach (KeyValuePair<GamePlayer, ResourceList> kvp in result)
            {
                // add list of resources
                ItemsControl resources = new ItemsControl();

                FrameworkElementFactory stackPanelElement = new FrameworkElementFactory(typeof(StackPanel));
                stackPanelElement.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
                resources.ItemsPanel = new ItemsPanelTemplate() { VisualTree = stackPanelElement};
                resources.Height = 90;

                Binding binding = new Binding()
                {
                    Converter = new ResourceConverter()
                };
                FrameworkElementFactory imageElement = new FrameworkElementFactory(typeof(Image));
                imageElement.SetBinding(Image.SourceProperty, binding);
                imageElement.SetValue(Image.HeightProperty, 80.0);
                imageElement.SetValue(Image.WidthProperty, 80.0);

                resources.ItemTemplate = new DataTemplate()
                {
                    VisualTree = imageElement
                };
                basePanel.Children.Add(resources);
                resources.ItemsSource = kvp.Value;
            }
        }
示例#4
0
        private static DataTemplate CreateTemplate()
        {
            DataTemplate template = new DataTemplate {DataType = typeof(UiDataProviderNode)};

            FrameworkElementFactory stackPanel = new FrameworkElementFactory(typeof(StackPanel));
            stackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);

            FrameworkElementFactory image = new FrameworkElementFactory(typeof(Image));
            image.SetValue(HeightProperty, 16d);
            image.SetValue(Image.SourceProperty, new Binding("Icon"));
            image.SetValue(MarginProperty, new Thickness(3));
            stackPanel.AppendChild(image);

            //FrameworkElementFactory icon = new FrameworkElementFactory(typeof(ContentPresenter));
            //icon.SetValue(HeightProperty, 16d);
            //icon.SetValue(ContentPresenter.ContentProperty, new Binding("Icon"));
            //icon.SetValue(MarginProperty, new Thickness(3));
            //stackPanel.AppendChild(icon);

            FrameworkElementFactory textBlock = new FrameworkElementFactory(typeof(TextBlock));
            textBlock.SetBinding(TextBlock.TextProperty, new Binding("Title"));
            textBlock.SetBinding(ToolTipProperty, new Binding("Description"));
            textBlock.SetValue(MarginProperty, new Thickness(3));
            stackPanel.AppendChild(textBlock);

            template.VisualTree = stackPanel;

            return template;
        }
        public TextureManager()
        {
            InitializeComponent();

            DataGridTemplateColumn col = new DataGridTemplateColumn();
            Binding imgBinding = new Binding("Name") { Converter = new Controls.PathToImageConverter() };
            FrameworkElementFactory imgFactory = new FrameworkElementFactory(typeof(Image));
            imgFactory.SetBinding(Image.SourceProperty, imgBinding);
            imgFactory.SetValue(Image.MaxHeightProperty, 64.0);
            imgFactory.SetValue(Image.MaxWidthProperty, 64.0);
            imgFactory.SetValue(Image.TagProperty, "PreviewImage");
            ((DataGridTemplateColumn)col).CellTemplate = new DataTemplate();
            ((DataGridTemplateColumn)col).CellTemplate.VisualTree = imgFactory;
            col.Header = "Preview";
            gridView.Columns.Add(col);

            formStack.Children.Add(textureForm_ = new ReflectiveForm(typeof(Urho.Texture)));
            texTree.DataContext = Project.inst().Textures;
            texTree.SelectedItemChanged += texTree_SelectedItemChanged;
            gridView.DataContext = flat_ = Project.inst().Textures.GetFlat();

            formStack.Children.Add(nothing_ = new NothingHere("Texture"));
            nothing_.Visibility = System.Windows.Visibility.Visible;
            textureForm_.Visibility = System.Windows.Visibility.Collapsed;
        }
示例#6
0
    public static void ApplyAutogeneratedColumnAttributes(DataGridAutoGeneratingColumnEventArgs e)
    {
      PropertyDescriptor pd = e.PropertyDescriptor as PropertyDescriptor;
      if (pd.Attributes[typeof(HiddenColumn)] != null)
      {
        e.Cancel = true;
        return;
      }

      DisplayNameAttribute nameAttribute = pd.Attributes[typeof(DisplayNameAttribute)] as DisplayNameAttribute;
      if (nameAttribute != null && !String.IsNullOrEmpty(nameAttribute.DisplayName))
      {
        e.Column.Header = nameAttribute.DisplayName;
      }

      ColumnWidth columnWidth = pd.Attributes[typeof(ColumnWidth)] as ColumnWidth;
      if (columnWidth != null)
      {
        e.Column.Width = columnWidth.Width;
      }

      if (e.PropertyType == typeof(double))
      {
        (e.Column as DataGridTextColumn).Binding.StringFormat = "{0:0.###}";
      }

			if (e.PropertyType == typeof(bool) && !e.Column.IsReadOnly)
			{
				var checkboxFactory = new FrameworkElementFactory(typeof(CheckBox));
				checkboxFactory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
				checkboxFactory.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
				checkboxFactory.SetBinding(CheckBox.IsCheckedProperty, new Binding(e.PropertyName) { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
				e.Column = new DataGridTemplateColumn { Header = e.Column.Header, CellTemplate = new DataTemplate { VisualTree = checkboxFactory }, SortMemberPath = e.Column.SortMemberPath };
			}
    }
示例#7
0
        private void GenerateMetaColumns()
        {
            while (_gridView.Columns.Count > 1)
            {
                _gridView.Columns.RemoveAt(1);
            }

            // dynamically generate columns for meta data 
            var container = theView.DataContext as ContainerVM;
            if (container != null)
            {

                foreach (var info in container.KnownMetaData)
                {
                    GridViewColumn col = new GridViewColumn
                    {
                        Header = info.Name,
                        HeaderContainerStyle = TryFindResource(string.Format("{0}AlignColHeader", info.HeaderAlignment)) as Style,
                        Width = info.Width,
                    };
                    var txt = new FrameworkElementFactory(typeof(TextBlock));
                    txt.SetBinding(TextBlock.TextProperty, new Binding(string.Format("MetaData[{0}].Value", info.Name)) { Converter = info.Formatter, ConverterParameter = info.FormatParameter });
                    txt.SetValue(TextBlock.TextTrimmingProperty, TextTrimming.CharacterEllipsis);
                    txt.SetValue(TextBlock.TextAlignmentProperty, info.ContentAlignment);
                    col.CellTemplate = new DataTemplate() { VisualTree = txt };

                    _gridView.Columns.Add(col);
                }
            }
        }
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var rule = item as RuleViewModel;
            if (rule == null)
                return null;

            FrameworkElementFactory checkBoxFactory = new FrameworkElementFactory(typeof(CheckBox));
            Binding isCheckedBinding = new Binding("IsSelected")
            {
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };
            checkBoxFactory.SetBinding(CheckBox.IsCheckedProperty, isCheckedBinding);

            FrameworkElementFactory textBlockFactory = new FrameworkElementFactory(typeof(TextBlock));
            textBlockFactory.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            textBlockFactory.SetValue(TextBlock.TextProperty, (rule.Index + 1).ToString());
            textBlockFactory.SetValue(TextBlock.MarginProperty, new Thickness(0, 5, 0, 0));

            FrameworkElementFactory stackPanelFactory = new FrameworkElementFactory(typeof(StackPanel));
            stackPanelFactory.AppendChild(checkBoxFactory);
            stackPanelFactory.AppendChild(textBlockFactory);

            return new DataTemplate { VisualTree = stackPanelFactory };
        }
示例#9
0
        public SelectFolderDesigner()
        {
            this.InlineEditorTemplate = new DataTemplate();

            var stack = new FrameworkElementFactory(typeof(DockPanel));
            stack.SetValue(DockPanel.LastChildFillProperty, true);

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

            editModeSwitch.SetValue(EditModeSwitchButton.TargetEditModeProperty, PropertyContainerEditMode.Dialog);
            editModeSwitch.SetValue(DockPanel.DockProperty, Dock.Right);

            stack.AppendChild(editModeSwitch);

            // Erstellen und Konfiguration des Labels
            var label = new FrameworkElementFactory(typeof(Label));
            //Binding labelBinding = new Binding("Value");

            // Setzen der Eigenschaften des Labels
            label.SetValue(ContentControl.ContentProperty, "Bitte den Dialog öffnen");
            label.SetValue(DockPanel.DockProperty, Dock.Left);

            stack.AppendChild(label);

            this.InlineEditorTemplate.VisualTree = stack;

            // Zuordnen des DataTemplates
            // this.InlineEditorTemplate = res["SelectFileEditorTemplate"] as DataTemplate;
        }
        public ColorWheel()
        {
            // Define the ItemsPanel template.
            FrameworkElementFactory factoryRadialPanel =
                            new FrameworkElementFactory(typeof(RadialPanel));
            ItemsPanel = new ItemsPanelTemplate(factoryRadialPanel);

            // Create the DataTemplate for the items.
            DataTemplate template = new DataTemplate(typeof(Brush));
            ItemTemplate = template;

            // Create a FrameworkElementFactory based on Rectangle.
            FrameworkElementFactory elRectangle =
                                new FrameworkElementFactory(typeof(Rectangle));
            elRectangle.SetValue(Rectangle.WidthProperty, 4.0);
            elRectangle.SetValue(Rectangle.HeightProperty, 12.0);
            elRectangle.SetValue(Rectangle.MarginProperty,
                                        new Thickness(1, 8, 1, 8));
            elRectangle.SetBinding(Rectangle.FillProperty, new Binding(""));

            // Use that factory for the visual tree.
            template.VisualTree = elRectangle;

            // Set the items in the ListBox.
            PropertyInfo[] props = typeof(Brushes).GetProperties();

            foreach (PropertyInfo prop in props)
                Items.Add((Brush)prop.GetValue(null, null));
        }
        public ListColorsEvenElegantlier()
        {
            Title = "List Colors Even Elegantlier";

            DataTemplate template = new DataTemplate(typeof(NamedBrush));
            FrameworkElementFactory factoryStack = new FrameworkElementFactory(typeof(StackPanel));
            factoryStack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            template.VisualTree = factoryStack;

            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"));
            factoryStack.AppendChild(factoryRectangle);

            FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock));
            factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            factoryTextBlock.SetValue(TextBlock.TextProperty, new Binding("Name"));
            factoryStack.AppendChild(factoryTextBlock);

            ListBox lstbox = new ListBox();
            lstbox.Width = 150;
            lstbox.Height = 150;
            Content = lstbox;

            lstbox.ItemTemplate = template;
            lstbox.ItemsSource = NamedBrush.All;

            lstbox.SelectedValuePath = "Brush";
            lstbox.SetBinding(ListBox.SelectedValueProperty, "Background");
            lstbox.DataContext = this;
        }
示例#12
0
        // Thumbを Canvasに追加
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            // 新規に Thumb を追加
            thb_x = 10;
            thb_y = 100;
            System.Windows.Controls.Primitives.Thumb thb;
            thb = new System.Windows.Controls.Primitives.Thumb();
            // Mouseでの移動、右クリックEvent登録
            thb.DragCompleted += new System.Windows.Controls.Primitives.DragCompletedEventHandler(mark_DragCompleted);
            thb.DragStarted += new System.Windows.Controls.Primitives.DragStartedEventHandler(mark_DragStarted);
            thb.DragDelta += new System.Windows.Controls.Primitives.DragDeltaEventHandler(mark_DragDelta);
            thb.MouseRightButtonDown += new MouseButtonEventHandler(thumb_MouseRightBtnDown);
            // Thumbの大きさと色指定
            thb.Width = 80;
            thb.Height = 20;
            thb.Name = "mark";
            // 要素指定
            FrameworkElementFactory element = new FrameworkElementFactory(typeof(TextBlock));
            element.SetValue(TextBlock.TextProperty, "TextBlock");
            element.SetValue(TextBlock.WidthProperty, 80.0);
            element.SetValue(TextBlock.HeightProperty, 20.0);
            //element.SetValue(TextBlock.BackgroundProperty, new SolidColorBrush(Colors.Aqua));
            var bmp = new BitmapImage(new Uri("migiya.png", UriKind.Relative));
            var br = new ImageBrush(bmp);
            element.SetValue(TextBlock.BackgroundProperty, br);

            //FrameworkElementFactory element = new FrameworkElementFactory(typeof(Button));
            //element.SetValue(Button.ContentProperty, "Button");
            //element.SetValue(Button.WidthProperty, 80.0);
            //element.SetValue(Button.HeightProperty, 20.0);
            //element.SetValue(Button.BackgroundProperty, new SolidColorBrush(Colors.Aqua));

            ControlTemplate template = new ControlTemplate(typeof(System.Windows.Controls.Primitives.Thumb));
            template.VisualTree = element;
            thb.Template = template;
            //thb.Background = Brushes.Green;
            //var bmp = new BitmapImage(new Uri("migiya.png", UriKind.Relative));
            //var br = new ImageBrush(bmp);
            //thb.Background = br;

            // 右クリックメニュー作成 ( BkBlue, BkLightBlue )
            ContextMenu cm = new ContextMenu();
            MenuItem mi1 = new MenuItem();
            mi1.Header = "BkBlue";
            mi1.Click += new RoutedEventHandler(thumbItem_MouseLeftBtnDown);
            cm.Items.Add(mi1);

            MenuItem mi2 = new MenuItem();
            mi2.Header = "BkLightBlue";
            mi2.Click += new RoutedEventHandler(thumbItem_MouseLeftBtnDown);
            cm.Items.Add(mi2);

            thb.ContextMenu = cm;       // Thumb に メニュー追加
            canvas1.Children.Add(thb);  // Canvas に Thumb追加

            // Canvas上のThumb表示位置指定
            Canvas.SetLeft(thb, 10);
            Canvas.SetTop(thb, 100);
        }
示例#13
0
 public void AddButtonColumn(string buttonText, int widthPercent, RoutedEventHandler clickHandler,Style style = null)
 {
     FrameworkElementFactory ef = new FrameworkElementFactory(typeof(Button));
     ef.SetValue(Button.StyleProperty, ResourceLoader.GetControlStyle("ButtonStyle"));
     ef.SetValue(Button.ContentProperty, buttonText);
     ef.AddHandler(Button.ClickEvent, clickHandler, true);
     AddColumn(ef, widthPercent, "","",style);
 }
        private DataTemplate BuildDataTemplate(Type viewModelType)
        {
            if (viewModelType == null)
            {
                throw new ArgumentNullException("viewModelType");
            }

            const int standardMargin = 2;
            var defaultMargin = new Thickness(standardMargin);

            var allProperties = viewModelType.GetProperties().ToList();
            var commandProperties = allProperties.Where(pi => pi.PropertyType.IsAssignableTo<ICommand>()).ToList();
            var scalarProperties =
                allProperties.Where(pi => !pi.PropertyType.IsAssignableFrom<ICommand>()).ToList();

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

            foreach (var scalarProperty in scalarProperties)
            {
                var textLineFactory = new FrameworkElementFactory(typeof (StackPanel));
                textLineFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
                string name = scalarProperty.Name;

                //stackpanel for each scalar property contains of 2 textblocks - one for caption, one for value
                var captionTextBlockFactory = new FrameworkElementFactory(typeof(TextBlock));
                captionTextBlockFactory.SetValue(TextBlock.TextProperty, name + ":");
                captionTextBlockFactory.SetValue(FrameworkElement.MarginProperty, defaultMargin);
                textLineFactory.AppendChild(captionTextBlockFactory);

                var valueTextBlockFactory = new FrameworkElementFactory(typeof(TextBlock));
                valueTextBlockFactory.SetBinding(TextBlock.TextProperty, new Binding(name));
                valueTextBlockFactory.SetValue(FrameworkElement.MarginProperty, defaultMargin);
                textLineFactory.AppendChild(valueTextBlockFactory);

                elementFactory.AppendChild(textLineFactory);
            }

            //Create all buttons for commands
            if (commandProperties.Any())
            {
                var buttonPanelFactory = new FrameworkElementFactory(typeof(StackPanel));
                buttonPanelFactory.SetValue(StackPanel.OrientationProperty, Orientation.Vertical);
                foreach (var commandProperty in commandProperties)
                {
                    var controlElementFactory = new FrameworkElementFactory(typeof(Button));
                    controlElementFactory.SetBinding(ButtonBase.CommandProperty, new Binding(commandProperty.Name));
                    controlElementFactory.SetValue(ContentControl.ContentProperty, commandProperty.Name);
                    buttonPanelFactory.AppendChild(controlElementFactory);
                }
                elementFactory.AppendChild(buttonPanelFactory);
            }

            return new DataTemplate
                       {
                           DataType = viewModelType,
                           VisualTree = elementFactory
                       };
        }
示例#15
0
 FrameworkElementFactory GetFactory(Brush back)
 {
     back.Opacity = 0.6;
     var fef = new FrameworkElementFactory(typeof(Ellipse));
     fef.SetValue(Ellipse.FillProperty, back);
     fef.SetValue(Ellipse.StrokeProperty, Brushes.White);
     fef.SetValue(Ellipse.StrokeThicknessProperty, (double)1);
     return fef;
 }
示例#16
0
 public void AddTextColumn(string bindingName,string headerText,int widthPercent,Style style = null)
 {
     FrameworkElementFactory ef = new FrameworkElementFactory(typeof(TextBlock));
     ef.SetValue(TextBlock.TextWrappingProperty, TextWrapping.Wrap);
     ef.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
     ef.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
     ef.SetValue(TextBlock.TextProperty, new Binding(bindingName));
     AddColumn(ef, widthPercent, headerText, bindingName, style);
 }
        public ListColorsEvenElegantlier()
        {
            Title = "List Colors Even Elegantlier";

            // Create a DataTemplate for the items.
            DataTemplate template = new DataTemplate(typeof(NamedBrush));

            // Create a FrameworkElementFactory based on StackPanel.
            FrameworkElementFactory factoryStack =
                                new FrameworkElementFactory(typeof(StackPanel));
            factoryStack.SetValue(StackPanel.OrientationProperty,
                                                Orientation.Horizontal);

            // Make that the root of the DataTemplate visual tree.
            template.VisualTree = factoryStack;

            // Create a FrameworkElementFactory based on 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"));
            // Add it to the StackPanel.
            factoryStack.AppendChild(factoryRectangle);

            // Create a FrameworkElementFactory based on TextBlock.
            FrameworkElementFactory factoryTextBlock =
                                new FrameworkElementFactory(typeof(TextBlock));
            factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty,
                                            VerticalAlignment.Center);
            factoryTextBlock.SetValue(TextBlock.TextProperty,
                                            new Binding("Name"));
            // Add it to the StackPanel.
            factoryStack.AppendChild(factoryTextBlock);

            // Create ListBox as content of window.
            ListBox lstbox = new ListBox();
            lstbox.Width = 150;
            lstbox.Height = 150;
            Content = lstbox;

            // Set the ItemTemplate property to the template created above.
            lstbox.ItemTemplate = template;

            // Set the ItemsSource to the array of NamedBrush objects.
            lstbox.ItemsSource = NamedBrush.All;

            // Bind the SelectedValue to window Background.
            lstbox.SelectedValuePath = "Brush";
            lstbox.SetBinding(ListBox.SelectedValueProperty, "Background");
            lstbox.DataContext = this;
        }
示例#18
0
		public static sw.FrameworkElementFactory ImageBlock()
		{
			var factory = new sw.FrameworkElementFactory(typeof(swc.Image));
			factory.SetValue(swc.Image.MaxHeightProperty, 16.0);
			factory.SetValue(swc.Image.MaxWidthProperty, 16.0);
			factory.SetValue(swc.Image.StretchDirectionProperty, swc.StretchDirection.DownOnly);
			factory.SetValue(swc.Image.MarginProperty, new sw.Thickness(0, 2, 2, 2));
			factory.SetBinding(swc.Image.SourceProperty, new sw.Data.Binding { Converter = new ImageConverter() });
			return factory;
		}
示例#19
0
        public void SetList(IList items)
        {
            if (items.Count > 0)
            {
                MainGrid.ColumnHeaders = new StringCollection();
                var itemType = items[0].GetType();
                foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(itemType))
                {
                    if (!descriptor.IsBrowsable)
                    {
                        continue;
                    }

                    var cd = new ColumnDefinition() { DataField = descriptor.Name };

                    if (descriptor.PropertyType == typeof(SolidColorBrush))
                    {
                        var colorDisplayTemplate = new DataTemplate { DataType = typeof(SolidColorBrush) };
                        var fef = new FrameworkElementFactory(typeof(Rectangle));
                        fef.SetBinding(Shape.FillProperty, new Binding(descriptor.Name));
                        fef.SetValue(WidthProperty, 12.0);
                        fef.SetValue(HeightProperty, 12.0);
                        fef.SetValue(MarginProperty, new Thickness(4, 0, 4, 0));
                        fef.SetValue(Shape.StrokeThicknessProperty, 1.0);
                        fef.SetValue(Shape.StrokeProperty, Brushes.Gainsboro);
                        colorDisplayTemplate.VisualTree = fef;
                        cd.DisplayTemplate = colorDisplayTemplate;

                        var colorEditTemplate = new DataTemplate { DataType = typeof(SolidColorBrush) };
                        var fefe = new FrameworkElementFactory(typeof(ColorPicker));
                        fefe.SetBinding(ColorPicker.SelectedColorProperty, new Binding(descriptor.Name) { Converter = new BrushToColorConverter() });
                        colorEditTemplate.VisualTree = fefe;
                        cd.EditTemplate = colorEditTemplate;
                    }

                    if (descriptor.PropertyType == typeof(string) && descriptor.Name.Contains("Image"))
                    {
                        var colorEditTemplate = new DataTemplate { DataType = typeof(string) };
                        var fefe = new FrameworkElementFactory(typeof(FilePicker));
                        fefe.SetBinding(FilePicker.FilePathProperty, new Binding(descriptor.Name));
                        colorEditTemplate.VisualTree = fefe;
                        cd.EditTemplate = colorEditTemplate;
                    }

                    var displayName = descriptor.DisplayName;
                    if (!String.IsNullOrEmpty(displayName))
                        cd.Header = descriptor.DisplayName;


                    MainGrid.ColumnDefinitions.Add(cd);
                }
                MainGrid.Content = items;
            }
        }
 /// <summary>
 /// Initializes the <see cref="TypeBasedDataTemplateSelector"/> class.
 /// </summary>
 static ModelItemTemplateSelector()
 {
     DefaultDataTemplate = new DataTemplate();
     var factory = new FrameworkElementFactory(typeof(TextBlock));
     var propertyPath = new Binding() { StringFormat = "Cannot find template for type {0}.  Optionally set the DataTemplate's x:Key property is set with the full name of this type." };
     factory.SetBinding(TextBlock.TextProperty, propertyPath);
     factory.SetValue(TextBlock.TextWrappingProperty, TextWrapping.Wrap);
     factory.SetValue(TextBlock.ForegroundProperty, Brushes.Red);
     DefaultDataTemplate.VisualTree = factory;
     DefaultDataTemplate.Seal();
 }
示例#21
0
		static DialogBackend()
		{
			var panelFactory = new FrameworkElementFactory (typeof (StackPanel));
			panelFactory.SetValue (StackPanel.OrientationProperty, SWC.Orientation.Horizontal);
			panelFactory.SetValue (StackPanel.MarginProperty, new Thickness (0, 7, 7, 7));

			PanelTemplate = new ItemsPanelTemplate (panelFactory);

			ButtonStyle.Setters.Add (new Setter (FrameworkElement.MarginProperty, new Thickness (7, 0, 0, 0)));
			ButtonStyle.Setters.Add (new Setter (FrameworkElement.MinWidthProperty, 80d));
		}
示例#22
0
		public void setBackgroundImage(string normal_image_uri, string pressed_image_uri)
		{
			Style style = new Style();

			style.Setters.Add(new Setter(ForegroundProperty, MetrialColor.getBrush(MetrialColor.Name.White)));

			// Normal
			ControlTemplate normal_button_template = new ControlTemplate(typeof(Button));

			FrameworkElementFactory normal_button_shape = new FrameworkElementFactory(typeof(Rectangle));
			normal_button_shape.SetValue(Shape.FillProperty, makeImageBrush(normal_image_uri));
			//normal_button_shape.SetValue(Shape.StrokeProperty, Brushes.White);
			//normal_button_shape.SetValue(Shape.StrokeThicknessProperty, 2.0);

			FrameworkElementFactory normal_button_content_presenter = new FrameworkElementFactory(typeof(ContentPresenter));
			normal_button_content_presenter.SetValue(ContentProperty, new TemplateBindingExtension(ContentProperty));
			normal_button_content_presenter.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
			normal_button_content_presenter.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center);

			FrameworkElementFactory normal_button_merged_element = new FrameworkElementFactory(typeof(Grid));
			normal_button_merged_element.AppendChild(normal_button_shape);
			normal_button_merged_element.AppendChild(normal_button_content_presenter);

			normal_button_template.VisualTree = normal_button_merged_element;
			style.Setters.Add(new Setter(TemplateProperty, normal_button_template));

			// For Pressed
			Trigger button_pressed_trigger = new Trigger();
			button_pressed_trigger.Property = Button.IsPressedProperty;
			button_pressed_trigger.Value = true;

			ControlTemplate pressed_button_template = new ControlTemplate(typeof(Button));

			FrameworkElementFactory pressed_button_shape = new FrameworkElementFactory(typeof(Rectangle));
			pressed_button_shape.SetValue(Shape.FillProperty, makeImageBrush(pressed_image_uri));
			//pressed_button_shape.SetValue(Shape.StrokeProperty, Brushes.White);
			//pressed_button_shape.SetValue(Shape.StrokeThicknessProperty, 2.0);

			FrameworkElementFactory pressed_button_button_content_presenter = new FrameworkElementFactory(typeof(ContentPresenter));
			pressed_button_button_content_presenter.SetValue(ContentProperty, new TemplateBindingExtension(ContentProperty));
			pressed_button_button_content_presenter.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
			pressed_button_button_content_presenter.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center);

			FrameworkElementFactory pressed_button_mreged_element = new FrameworkElementFactory(typeof(Grid));
			pressed_button_mreged_element.AppendChild(pressed_button_shape);
			pressed_button_mreged_element.AppendChild(pressed_button_button_content_presenter);

			pressed_button_template.VisualTree = pressed_button_mreged_element;
			button_pressed_trigger.Setters.Add(new Setter(TemplateProperty, pressed_button_template));

			style.Triggers.Add(button_pressed_trigger);

			button.Style = style;
		}
        public void Initialize()
        {
            GridView gridView = new GridView();
            GridViewColumn column = null;
            column = new GridViewColumn();
            column.Header = "    LineInfo    ";
            column.Width = double.NaN;
            System.Windows.DataTemplate template = new System.Windows.DataTemplate();
            System.Windows.FrameworkElementFactory textBox =
                new System.Windows.FrameworkElementFactory(typeof(TextBox));
            Binding bd = new Binding("Line");
            bd.Mode = BindingMode.TwoWay;
            textBox.SetValue(TextBox.IsEnabledProperty, true);
            textBox.SetBinding(TextBox.TextProperty, bd);
            template.VisualTree = textBox;
            column.CellTemplate = template;
            gridView.Columns.Add(column);

            column = new GridViewColumn();
            column.Header = "    OutLineConveyor    ";
            column.Width = double.NaN;
            template = new System.Windows.DataTemplate();
            System.Windows.FrameworkElementFactory comboBox =
                new System.Windows.FrameworkElementFactory(typeof(ComboBox));
            bd = new Binding("LineConveyor");
            bd.Mode = BindingMode.TwoWay;
            comboBox.SetValue(ComboBox.IsEnabledProperty, true);
            comboBox.SetValue(ComboBox.ItemsSourceProperty, Enum.GetNames(typeof(OutLineConveyor)));
            comboBox.SetBinding(ComboBox.TextProperty, bd);
            template.VisualTree = comboBox;
            column.CellTemplate = template;
            gridView.Columns.Add(column);

            column = new GridViewColumn();
            column.Header = "    LotCardPrinting    ";
            column.Width = (double.NaN);
            template = new System.Windows.DataTemplate();
            System.Windows.FrameworkElementFactory comboBoxPrinting =
                new System.Windows.FrameworkElementFactory(typeof(ComboBox));
            bd = new Binding("LotCardPrint");
            bd.Mode = BindingMode.TwoWay;
            comboBoxPrinting.SetValue(ComboBox.IsEnabledProperty, true);
            comboBoxPrinting.SetValue(ComboBox.ItemsSourceProperty, Enum.GetNames(typeof(LotCardPrinting)));
            comboBoxPrinting.SetBinding(ComboBox.TextProperty, bd);
            template.VisualTree = comboBoxPrinting;
            column.CellTemplate = template;
            gridView.Columns.Add(column);

            UIUtility.SetListViewContentAlignmentStrech(listViewStepList);
            listViewStepList.View = gridView;
            listViewStepList.ItemsSource = Equipment.EquipmentManager.Instance.MainEquip.Config.OutLineSelectInfo;
        }
 private void addCustomColumn(string columnName)
 {
     DataGridTemplateColumn dt = new DataGridTemplateColumn();
     dt.Header = columnName;
     FrameworkElementFactory editButton = new FrameworkElementFactory(typeof(Button), string.Format("{0}Button", columnName.ToLower()));
     editButton.SetValue(Button.ContentProperty, columnName);
     editButton.SetValue(Button.NameProperty, string.Format("{0}Button", columnName.ToLower()));
     editButton.AddHandler(Button.ClickEvent, new RoutedEventHandler(delete_Click));
     DataTemplate cellTemplate = new DataTemplate();
     cellTemplate.VisualTree = editButton;
     dt.CellTemplate = cellTemplate;
     resultsGrid.Columns.Add(dt);
 }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var factory = new FrameworkElementFactory(typeof(AnimatedUniformGrid));

            factory.SetValue(AnimatedUniformGrid.RowsProperty, 5);
            factory.SetValue(AnimatedUniformGrid.ColumnsProperty, 5);


            this.listname.ItemsPanel = new ItemsPanelTemplate(factory);


            // dev1 test1
        }
示例#26
0
        public BuildButtonFactory()
        {
            Title = "Build Button Factory";

            ControlTemplate template = new ControlTemplate(typeof(Button));

            FrameworkElementFactory factoryBorder = new FrameworkElementFactory(typeof(Border));
            factoryBorder.Name = "border";
            factoryBorder.SetValue(Border.BorderBrushProperty, Brushes.Red);
            factoryBorder.SetValue(Border.BorderThicknessProperty, new Thickness(3));
            factoryBorder.SetValue(Border.BackgroundProperty, SystemColors.ControlLightBrush);

            FrameworkElementFactory factoryContent = new FrameworkElementFactory(typeof(ContentPresenter));
            factoryContent.Name = "content";
            factoryContent.SetValue(ContentPresenter.ContentProperty,
                new TemplateBindingExtension(Button.ContentProperty));
            factoryContent.SetValue(ContentPresenter.MarginProperty,
                new TemplateBindingExtension(Button.PaddingProperty));

            factoryBorder.AppendChild(factoryContent);
            template.VisualTree = factoryBorder;

            Trigger trig = new Trigger();
            trig.Property = UIElement.IsMouseOverProperty;
            trig.Value = true;

            Setter set = new Setter();
            set.Property = Border.CornerRadiusProperty;
            set.Value = new CornerRadius(24);
            set.TargetName = "border";
            trig.Setters.Add(set);

            set = new Setter();
            set.Property = Control.FontStyleProperty;
            set.Value = FontStyles.Italic;
            trig.Setters.Add(set);

            template.Triggers.Add(trig);

            Button btn = new Button();
            btn.Template = template;
            btn.Content = "Button with Custom Template";
            btn.Padding = new Thickness(20);
            btn.FontSize = 48;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.VerticalAlignment = VerticalAlignment.Center;
            btn.Click += ButtonOnClick;

            Content = btn;
        }
示例#27
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;
         if (BShowDetails)
         {
             gvc.Width = (_listview.ActualWidth - 65) / dt.Columns.Count;
         }
         else
         {
             gvc.Width = (_listview.ActualWidth - 25) / dt.Columns.Count;
         }
         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;
 }
        public ColorComboBox()
            : base()
        {
            // A width of 120 seems to cover the longest string by itself (in English).
            this.Width = 148;
            this.Height = 26;

            // Create a DataTemplate for the items
            DataTemplate template = new DataTemplate(typeof(NamedColor));

            // Create a FrameworkElementFactory based on StackPanel
            FrameworkElementFactory factoryStack = new FrameworkElementFactory(typeof(StackPanel));
            factoryStack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);

            // Make that the root of the DataTemplate visual tree.
            template.VisualTree = factoryStack;

            // Create a FrameworkElementFactory based on 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.SetValue(Rectangle.FillProperty, new Binding("Brush"));

            // Add it to the StackPanel.
            factoryStack.AppendChild(factoryRectangle);

            // Create a FrameworkElementFactory based on TextBlock.
            FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock));
            factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            factoryTextBlock.SetValue(TextBlock.TextProperty, new Binding("Name"));

            // Add it to the StackPanel.
            factoryStack.AppendChild(factoryTextBlock);

            // Set the ItemTemplate property to the template created above.
            this.ItemTemplate = template;

            // I'm setting this at the dropdown event, to save loading time.
            //this.ItemsSource = NamedColor.All;
            //this.DisplayMemberPath = "Name";
            this.SelectedValuePath = "Color";

            //DropDownOpened += new EventHandler(OnDropDownOpened);
            FillMyself();

            SelectionChanged += new SelectionChangedEventHandler(OnSelectionChanged);
        }
示例#29
0
        public TreeGridViewColumn()
            : base()
        {
            ResourceDictionary resourceDictionary = new ResourceDictionary();
            resourceDictionary.Source = new Uri("pack://application:,,,/Yuhan.WPF.TreeListView;component/Resources/TreeListView.xaml");

            //this.CellTemplate = resourceDictionary["CellTemplate"] as DataTemplate;

            DataTemplate template = new DataTemplate();

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

            Expander = new FrameworkElementFactory(typeof(ToggleButton));
            Expander.Name = "Expander";
            Expander.SetValue(ToggleButton.StyleProperty, resourceDictionary["ExpandCollapseToggleStyle"] as Style);
            Expander.SetBinding(ToggleButton.VisibilityProperty, new Binding()
            {
                Source = this.Expandable,
                Converter = new BooleanToVisibilityConverter()
            });
            Expander.SetBinding(ToggleButton.MarginProperty, new Binding("Level")
            {
                Converter = new LevelToIndentConverter(),
                RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(TreeListViewItem), 1)
            });
            Expander.SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsExpanded")
            {
                RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(TreeListViewItem), 1)
            });
            Expander.SetValue(ToggleButton.ClickModeProperty, ClickMode.Press);

            ContentControlFactory = new FrameworkElementFactory(typeof(ContentControl));
            ContentControlFactory.SetBinding(ContentControl.ContentProperty, new Binding(FieldName));

            factory.AppendChild(Expander);
            factory.AppendChild(ContentControlFactory);

            template.VisualTree = factory;
            template.Triggers.Add(new DataTrigger()
            {
                Binding = new Binding("HasItems")
                {
                    RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(TreeListViewItem), 1),
                },
                Value = false,
                Setters = { new Setter(ToggleButton.VisibilityProperty, Visibility.Hidden, "Expander") }
            });
            this.CellTemplate = template;
        }
        public ColorGridBox()
        {
            // Define the ItemsPanel template.
            FrameworkElementFactory factoryUnigrid =
                            new FrameworkElementFactory(typeof(UniformGrid));
            factoryUnigrid.SetValue(UniformGrid.ColumnsProperty, 8);
            ItemsPanel = new ItemsPanelTemplate(factoryUnigrid);

            // Add items to the ListBox.
            foreach (string strColor in strColors)
            {
                // Create Rectangle and add to ListBox.
                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);

                // Create ToolTip for Rectangle.
                ToolTip tip = new ToolTip();
                tip.Content = strColor;
                rect.ToolTip = tip;
            }
            // Indicate that SelectedValue is Fill property of Rectangle item.
            SelectedValuePath = "Fill";
        }
示例#31
0
        public static sw.FrameworkElementFactory ItemTemplate(bool editable, swd.RelativeSource relativeSource = null)
        {
            var factory = new sw.FrameworkElementFactory(typeof(swc.StackPanel));

            factory.SetValue(swc.StackPanel.OrientationProperty, swc.Orientation.Horizontal);
            factory.AppendChild(ImageBlock());
            factory.AppendChild(editable ? EditableBlock(relativeSource) : TextBlock());
            return(factory);
        }
示例#32
0
        public static sw.FrameworkElementFactory TextBlock()
        {
            var factory = new sw.FrameworkElementFactory(typeof(swc.TextBlock));

            factory.SetBinding(swc.TextBlock.TextProperty, new sw.Data.Binding {
                Path = TextPath
            });
            factory.SetValue(swc.TextBlock.MarginProperty, new sw.Thickness(2));
            return(factory);
        }
示例#33
0
        public static sw.FrameworkElementFactory TextBlock(bool setMargin = true)
        {
            var factory = new sw.FrameworkElementFactory(typeof(swc.TextBlock));

            factory.SetBinding(swc.TextBlock.TextProperty, new sw.Data.Binding {
                Path = new sw.PropertyPath("Text")
            });
            if (setMargin)
            {
                factory.SetValue(sw.FrameworkElement.MarginProperty, new sw.Thickness(2));
            }
            return(factory);
        }
示例#34
0
        private void AddRatingColumn(string header, int width, string bindingPath)
        {
            DataGridTemplateColumn nc = new DataGridTemplateColumn();

            System.Windows.DataTemplate template = new System.Windows.DataTemplate();

            System.Windows.FrameworkElementFactory factoryRatingControl = new System.Windows.FrameworkElementFactory(typeof(RatingUserControl));

            System.Windows.Data.Binding binding = new System.Windows.Data.Binding(bindingPath);
            //binding.Converter = new Int32Converter();
            factoryRatingControl.SetBinding(RatingUserControl.RatingProperty, binding);
            factoryRatingControl.SetValue(RatingUserControl.HorizontalAlignmentProperty, System.Windows.HorizontalAlignment.Left);
            factoryRatingControl.SetValue(RatingUserControl.ReadOnlyProperty, true);

            template.VisualTree = factoryRatingControl;

            nc.CellTemplate = template;
            nc.Header       = header;
            nc.Width        = width;
            nc.IsReadOnly   = true;
            dataGrid.Columns.Add(nc);
        }
示例#35
0
        private DockPanel CreateUI()
        {
            DockPanel collision_dock_panel = new DockPanel()
            {
                LastChildFill = true
            };

            StackPanel collision_stack_panel = new StackPanel()
            {
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                VerticalAlignment   = System.Windows.VerticalAlignment.Stretch,
            };

            RowDefinition tree_row       = new RowDefinition();
            RowDefinition splitter_row   = new RowDefinition();
            RowDefinition properties_row = new RowDefinition();

            tree_row.Height          = System.Windows.GridLength.Auto;
            tree_row.MaxHeight       = 500;
            tree_row.MinHeight       = 10;
            splitter_row.Height      = System.Windows.GridLength.Auto;
            properties_row.Height    = System.Windows.GridLength.Auto;
            properties_row.MinHeight = 80;

            Grid col_grid = new Grid();

            col_grid.RowDefinitions.Add(tree_row);
            col_grid.RowDefinitions.Add(splitter_row);
            col_grid.RowDefinitions.Add(properties_row);

            System.Windows.HierarchicalDataTemplate template = new System.Windows.HierarchicalDataTemplate(typeof(CollisionGroupNode));
            template.ItemsSource = new Binding("Children");

            System.Windows.FrameworkElementFactory tb = new System.Windows.FrameworkElementFactory(typeof(TextBlock));
            tb.SetBinding(TextBlock.TextProperty, new Binding("Name"));
            tb.SetValue(TextBlock.ForegroundProperty, Brushes.Black);

            template.VisualTree = tb;

            m_CollisionTree = new TreeView()
            {
                VerticalAlignment   = System.Windows.VerticalAlignment.Stretch,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                ItemTemplate        = template
            };
            m_CollisionTree.SelectedItemChanged        += M_test_tree_SelectedItemChanged;
            m_CollisionTree.PreviewMouseLeftButtonDown += OnItemMouseDoubleClick;

            Grid.SetRow(m_CollisionTree, 0);

            GridSplitter splitter = new GridSplitter()
            {
                Height              = 5,
                VerticalAlignment   = System.Windows.VerticalAlignment.Top,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch
            };

            Grid.SetRow(splitter, 1);

            WDetailsView actor_details = new WDetailsView()
            {
                Name = "Details",
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                VerticalAlignment   = System.Windows.VerticalAlignment.Stretch,
                DataContext         = DetailsViewModel
            };

            GroupBox actor_prop_box = new GroupBox()
            {
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                VerticalAlignment   = System.Windows.VerticalAlignment.Stretch,
                Header  = "Properties",
                Content = actor_details,
            };

            Grid.SetRow(actor_prop_box, 2);

            col_grid.Children.Add(m_CollisionTree);
            col_grid.Children.Add(splitter);
            col_grid.Children.Add(actor_prop_box);

            DockPanel.SetDock(collision_stack_panel, Dock.Top);

            collision_stack_panel.Children.Add(col_grid);
            collision_dock_panel.Children.Add(collision_stack_panel);

            return(collision_dock_panel);
        }
示例#36
0
        private void CreateHeader(ColumnFieldCollection fields)
        {
            dataGrid.Columns.Clear();

            //Int32Converter int32Conv = new Int32Converter();

            int i = 0;

            foreach (ColumnField field in fields)
            {
                Type   columnType = DataBase.GetTypeByField(field.Field);
                int    width      = field.Width;
                string columnName = DataBase.GetNameOfField(field.Field, false);

                switch (field.Field)
                {
                case Field.Rating:
                {
                    DataGridRatingColumn nc = new DataGridRatingColumn();

                    System.Windows.DataTemplate template = new System.Windows.DataTemplate();

                    System.Windows.FrameworkElementFactory factoryRatingControl = new System.Windows.FrameworkElementFactory(typeof(RatingUserControl));

                    System.Windows.Data.Binding binding = new System.Windows.Data.Binding("Items[" + i + "]");
                    binding.Mode = BindingMode.TwoWay;
                    //binding.Converter = int32Conv;
                    factoryRatingControl.SetBinding(RatingUserControl.RatingProperty, binding);
                    factoryRatingControl.SetValue(RatingUserControl.HorizontalAlignmentProperty, System.Windows.HorizontalAlignment.Left);
                    factoryRatingControl.AddHandler(RatingUserControl.MouseLeftButtonDownEvent, new MouseButtonEventHandler(RatingCell_MouseLeftButtonDown));

                    nc.SetValue(DataGridExtensions.FieldProperty, field.Field);
                    //factoryRatingControl.SetValue(RatingUserControl.ReadOnlyProperty, true);

                    template.VisualTree = factoryRatingControl;
                    nc.CanUserSort      = true;
                    nc.CellTemplate     = template;
                    //nc.CellEditingTemplate = template;
                    nc.Header = columnName;
                    nc.Width  = width;
                    // Auf Read-Only setzen, da wir das manuell machen (im MouseLeftButtonDown)
                    nc.IsReadOnly     = true;
                    nc.SortMemberPath = "Items[" + i + "]";

                    dataGrid.Columns.Add(nc);
                    break;
                }

                case Field.Comment:
                {
                    DataGridTemplateColumn newMultilineColumn = new DataGridTemplateColumn();
                    newMultilineColumn.Width  = field.Width;
                    newMultilineColumn.Header = DataBase.GetNameOfField(field.Field);
                    newMultilineColumn.SetValue(DataGridExtensions.FieldProperty, field.Field);

                    DataTemplate multilineCelltemplate = this.FindResource("CommentTemplate") as DataTemplate;
                    newMultilineColumn.CellTemplate        = multilineCelltemplate;
                    newMultilineColumn.CellEditingTemplate = multilineCelltemplate;

                    dataGrid.Columns.Add(newMultilineColumn);
                    break;
                }

                default:
                {
                    DataGridMaxLengthTextColumn nc = new DataGridMaxLengthTextColumn();
                    nc.SetValue(DataGridExtensions.FieldProperty, field.Field);
                    System.Windows.Data.Binding binding = new System.Windows.Data.Binding("Items[" + i + "]");
                    if (field.Field == Field.TotalLength)
                    {
                        binding.Converter = new Big3.Hitbase.Miscellaneous.LengthConverter();
                    }
                    else if (field.Field == Field.Price)
                    {
                        binding.Converter = new PriceConverter();
                    }
                    else if (field.Field == Field.Date)
                    {
                        binding.Converter          = new DataBaseDateConverter();
                        binding.ConverterParameter = this.DataBase;
                    }
                    else if (field.Field == Field.AlbumType)
                    {
                        binding.Converter = new AlbumTypeConverter();
                        nc.IsReadOnly     = true;
                    }
                    else if (IsUserFieldDateFormat(field.Field))
                    {
                        binding.Converter = new UserFieldDateConverter();
                    }
                    else if (DataBase.GetTypeByField(field.Field) == typeof(int))
                    {
                        binding.Converter = new MyInt32Converter();
                    }
                    else if (DataBase.GetTypeByField(field.Field) == typeof(bool))
                    {
                        binding.Converter = new BoolConverter();
                    }

                    nc.Binding = binding;
                    nc.Header  = columnName;
                    nc.Width   = width;

                    if (DataBase.GetTypeByField(field.Field) == typeof(string))
                    {
                        nc.MaxLength = DataBase.GetMaxStringLength(field.Field);
                    }
                    //nc.IsReadOnly = true;

                    dataGrid.Columns.Add(nc);
                    break;
                }
                }

                i++;
            }

            CurrentFields = fields;
        }