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 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 }; }
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; }
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 static sw.FrameworkElementFactory ItemTemplate () { var factory = new sw.FrameworkElementFactory (typeof (swc.StackPanel)); factory.SetValue (swc.StackPanel.OrientationProperty, swc.Orientation.Horizontal); factory.AppendChild (ImageBlock ()); factory.AppendChild (TextBlock ()); return factory; }
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; }
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 }; }
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); }
public static sw.FrameworkElementFactory ItemTemplate() { var factory = new sw.FrameworkElementFactory(typeof(swc.StackPanel)); factory.SetValue(swc.StackPanel.OrientationProperty, swc.Orientation.Horizontal); factory.AppendChild(ImageBlock()); factory.AppendChild(TextBlock()); return(factory); }
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; }
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 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; }
private DataTemplate GetTreeHeaderDataTemplate() { DataTemplate _dataTemplate = new DataTemplate(); FrameworkElementFactory _stackPanel = new FrameworkElementFactory(typeof(StackPanel)); _stackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); FrameworkElementFactory _image = new FrameworkElementFactory(typeof(Image)); _image.SetValue(Image.SnapsToDevicePixelsProperty,true); _image.SetBinding(Image.SourceProperty, new Binding() { Converter = new ImageSourceConvert() }); FrameworkElementFactory _textBlock = new FrameworkElementFactory(typeof(TextBlock)); _textBlock.SetBinding(TextBlock.TextProperty, new Binding()); _stackPanel.AppendChild(_image); _stackPanel.AppendChild(_textBlock); _dataTemplate.VisualTree = _stackPanel; return _dataTemplate; }
internal static FrameworkElementFactory CreateBoundColumnTemplate (ApplicationContext ctx, Widget parent, CellViewCollection views, string dataPath = ".") { if (views.Count == 1) return CreateBoundCellRenderer(ctx, parent, views[0], dataPath); FrameworkElementFactory container = new FrameworkElementFactory (typeof (StackPanel)); container.SetValue (StackPanel.OrientationProperty, System.Windows.Controls.Orientation.Horizontal); foreach (CellView view in views) { var factory = CreateBoundCellRenderer(ctx, parent, view, dataPath); factory.SetValue(FrameworkElement.MarginProperty, CellMargins); if (view.VisibleField != null) { var binding = new Binding(dataPath + "[" + view.VisibleField.Index + "]"); binding.Converter = new BooleanToVisibilityConverter(); factory.SetBinding(UIElement.VisibilityProperty, binding); } else if (!view.Visible) factory.SetValue(UIElement.VisibilityProperty, Visibility.Collapsed); container.AppendChild(factory); } return container; }
public DataGridDbObjectColumn(string bindingPath, Action<DbObject,string,DbObject> clickHandler) { this.bindingPath = bindingPath; this.clickHandler = clickHandler; // var stackPanelFactory = new FrameworkElementFactory(typeof (StackPanel)); // stackPanelFactory.SetValue(StackPanel.OrientationProperty,Orientation.Horizontal); // stackPanelFactory.SetValue(Control.MarginProperty, new Thickness(1)); // stackPanelFactory.SetValue(Control.WidthProperty,300.0); var gridFactory = new FrameworkElementFactory(typeof (Grid)); gridFactory.SetValue(Control.MarginProperty, new Thickness(1)); var columnDefinitionFactory1 = new FrameworkElementFactory(typeof(ColumnDefinition)); columnDefinitionFactory1.SetValue(ColumnDefinition.WidthProperty,new GridLength(1,GridUnitType.Star)); gridFactory.AppendChild(columnDefinitionFactory1); var columnDefinitionFactory2 = new FrameworkElementFactory(typeof(ColumnDefinition)); columnDefinitionFactory2.SetValue(ColumnDefinition.WidthProperty,GridLength.Auto); gridFactory.AppendChild(columnDefinitionFactory2); var textBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); textBlockFactory.SetBinding(TextBlock.TextProperty,new Binding(bindingPath)); textBlockFactory.SetValue(Control.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); // textBlockFactory.AddHandler(UIElement.MouseDownEvent,new MouseButtonEventHandler(OnClick)); var buttonFactory = new FrameworkElementFactory(typeof (Button)); buttonFactory.AddHandler(Button.ClickEvent, new RoutedEventHandler(OnClick),true); buttonFactory.SetValue(Button.ContentProperty,"..."); // buttonFactory.SetValue(Button.ContentProperty,new Viewbox); buttonFactory.SetValue(Button.HeightProperty,16.0); buttonFactory.SetValue(Button.PaddingProperty,new Thickness(1)); buttonFactory.SetValue(Button.HorizontalAlignmentProperty,HorizontalAlignment.Right); // buttonFactory.SetValue(Button.MarginProperty,new Thickness(1)); // stackPanelFactory.AppendChild(textBlockFactory); // stackPanelFactory.AppendChild(buttonFactory); gridFactory.AppendChild(textBlockFactory); gridFactory.AppendChild(buttonFactory); CellTemplate = new DataTemplate(){VisualTree = gridFactory}; // CellTemplate.Seal(); // CellEditingTemplate = CellTemplate; }
/// <summary> /// </summary> /// <param name="image"> </param> /// <param name="name"> </param> /// <returns> </returns> public static DataTemplate ImageHeader(BitmapImage image, string name) { var dataTemplate = new DataTemplate(); var stackPanelFactory = new FrameworkElementFactory(typeof (StackPanel)); var imageFactory = new FrameworkElementFactory(typeof (Image)); var labelFactory = new FrameworkElementFactory(typeof (Label)); imageFactory.SetValue(FrameworkElement.HeightProperty, (double) 24); imageFactory.SetValue(FrameworkElement.WidthProperty, (double) 24); imageFactory.SetValue(FrameworkElement.ToolTipProperty, name); imageFactory.SetValue(Image.SourceProperty, image); var binding = BindingHelper.VisibilityBinding(Settings.Default, "EnableHelpLabels"); labelFactory.SetBinding(UIElement.VisibilityProperty, binding); labelFactory.SetValue(ContentControl.ContentProperty, name); stackPanelFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); stackPanelFactory.AppendChild(imageFactory); stackPanelFactory.AppendChild(labelFactory); dataTemplate.VisualTree = stackPanelFactory; return dataTemplate; }
public UserDataEditor() { InlineEditorTemplate = new DataTemplate(); var stack = new FrameworkElementFactory(typeof (StackPanel)); stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); var editModeSwitch = new FrameworkElementFactory(typeof (EditModeSwitchButton)); editModeSwitch.SetValue(EditModeSwitchButton.TargetEditModeProperty, PropertyContainerEditMode.Dialog); stack.AppendChild(editModeSwitch); InlineEditorTemplate.VisualTree = stack; }
/// <summary> /// NoteBubbleViewModel Constructor. /// </summary> public MelodyBubbleViewModel(MelodyBubble mb, ScatterView sv, SessionViewModel s) : base(s) { MelodyBubble = mb; SVItem = new ScatterViewItem(); ParentSV = sv; Random r = new Random(); SVItem.Center = new Point(r.Next((int)sv.ActualWidth), r.Next((int)(635 * sv.ActualHeight / 1080), (int)sv.ActualHeight)); SVItem.CanScale = false; SVItem.HorizontalAlignment = HorizontalAlignment.Center; SVItem.CanRotate = false; SVItem.HorizontalAlignment = HorizontalAlignment.Center; FrameworkElementFactory bubbleImage = new FrameworkElementFactory(typeof(Image)); bubbleImage.SetValue(Image.SourceProperty, new ThemeViewModel(SessionVM.Session.Theme, SessionVM).GetMelodyBubbleImageSource(mb.Melody.gesture)); bubbleImage.SetValue(Image.IsHitTestVisibleProperty, false); bubbleImage.SetValue(Image.WidthProperty, (135.0 / 1920.0) * SessionVM.SessionSVI.ActualWidth); bubbleImage.SetValue(Image.HeightProperty, (135.0 / 1080.0) * SessionVM.SessionSVI.ActualHeight); FrameworkElementFactory touchZone = new FrameworkElementFactory(typeof(Ellipse)); touchZone.SetValue(Ellipse.FillProperty, Brushes.Transparent); touchZone.SetValue(Ellipse.MarginProperty, new Thickness(15)); FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid)); grid.AppendChild(bubbleImage); grid.AppendChild(touchZone); ControlTemplate ct = new ControlTemplate(typeof(ScatterViewItem)); ct.VisualTree = grid; Style bubbleStyle = new Style(typeof(ScatterViewItem)); bubbleStyle.Setters.Add(new Setter(ScatterViewItem.TemplateProperty, ct)); SVItem.Style = bubbleStyle; Animation = new MelodyBubbleAnimation(this, SessionVM); }
public FilePickerEditor() { 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); this.InlineEditorTemplate.VisualTree = stack; }
public static void Register(ResourceDictionary resources) { var textBoxTemplate = new FrameworkElementFactory(typeof(TextBoxTemplate)); textBoxTemplate.AppendChild(new FrameworkElementFactory(typeof(ScrollViewer), "PART_ContentHost")); var controlTemplate = new ControlTemplate(typeof(TextBox)); controlTemplate.VisualTree = textBoxTemplate; var style = new Style(typeof(TextBox)); style.Setters.Add(new Setter(Control.TemplateProperty, controlTemplate)); resources.Add(typeof(TextBox), style); }
public CustomInlineEditor() { this.InlineEditorTemplate = new DataTemplate(); FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel)); FrameworkElementFactory slider = new FrameworkElementFactory(typeof(Slider)); Binding sliderBinding = new Binding("Value"); sliderBinding.Mode = BindingMode.TwoWay; slider.SetValue(Slider.MinimumProperty, 0.0); slider.SetValue(Slider.MaximumProperty, 100.0); slider.SetValue(Slider.ValueProperty, sliderBinding); stack.AppendChild(slider); FrameworkElementFactory textb = new FrameworkElementFactory(typeof(TextBox)); Binding textBinding = new Binding("Value"); textb.SetValue(TextBox.TextProperty, textBinding); textb.SetValue(TextBox.IsEnabledProperty, false); stack.AppendChild(textb); this.InlineEditorTemplate.VisualTree = stack; }
private void AddTemplateContent(FrameworkElementFactory root, DependencyObject obj) { var element = new FrameworkElementFactory(obj.GetType()); root.AppendChild(element); for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child != null) { AddTemplateContent(element, child); } } }
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; }
internal static FrameworkElementFactory CreateBoundColumnTemplate (ApplicationContext ctx, Widget parent, CellViewCollection views, string dataPath = ".") { if (views.Count == 1) return CreateBoundCellRenderer(ctx, parent, views[0], dataPath); FrameworkElementFactory container = new FrameworkElementFactory (typeof (StackPanel)); container.SetValue (StackPanel.OrientationProperty, System.Windows.Controls.Orientation.Horizontal); foreach (CellView view in views) { container.AppendChild(CreateBoundCellRenderer(ctx, parent, view, dataPath)); } return container; }
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); }
static DataTemplateImpl() { //set up the grid FrameworkElementFactory gridFactory = new FrameworkElementFactory(typeof(Grid)); gridFactory.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); gridFactory.AddHandler(Grid.LoadedEvent, (RoutedEventHandler)OnExpanderHeaderItemLoaded); //set up the content presenter FrameworkElementFactory presenterHolder = new FrameworkElementFactory(typeof(ContentPresenter)); presenterHolder.SetBinding(ContentPresenter.ContentProperty, new Binding("Content") { RelativeSource = RelativeSource.TemplatedParent }); gridFactory.AppendChild(presenterHolder); GridFactory = gridFactory; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var dv = value as DataView; if (dv != null) { var gridView = new GridView(); var cols = dv.ToTable().Columns; foreach (DataColumn item in cols) { // This section turns off the RecogniseAccessKey setting in the column header // which allows it to display underscores correctly. var hdrTemplate = new DataTemplate(); var contentPresenter = new FrameworkElementFactory(typeof(Border)); contentPresenter.SetValue(ContentPresenter.RecognizesAccessKeyProperty,false); var txtBlock = new FrameworkElementFactory(typeof(TextBlock)); txtBlock.SetValue(TextBlock.TextProperty, item.Caption); contentPresenter.AppendChild(txtBlock); hdrTemplate.VisualTree = contentPresenter; var cellTemplate = new DataTemplate(); var cellTxtBlock = new FrameworkElementFactory(typeof(TextBlock)); // Adding square brackets around the bind will escape any column names with the following "special" binding characters . / ( ) [ ] cellTxtBlock.SetBinding(TextBlock.TextProperty, new Binding("[" + item.ColumnName + "]") ); cellTxtBlock.SetValue(TextBlock.TextTrimmingProperty, TextTrimming.CharacterEllipsis); cellTemplate.VisualTree = cellTxtBlock; var gvc = new GridViewColumn { CellTemplate = cellTemplate, Width = Double.NaN, HeaderTemplate = hdrTemplate }; gridView.Columns.Add(gvc); } return gridView; } return Binding.DoNothing; }
private static DataTemplate CreateArchiveListingTemplate(bool hierarchical) { DataTemplate template; if (hierarchical) { //template = new HierarchicalDataTemplate {DataType = typeof(UiArchiveNodeOld)}; //((HierarchicalDataTemplate)template).ItemsSource = new Binding("OrderedHierarchyChilds"); template = new HierarchicalDataTemplate {DataType = typeof(UiContainerNode)}; ((HierarchicalDataTemplate)template).ItemsSource = new Binding("BindableHierarchyChilds"); } else { //template = new DataTemplate {DataType = typeof(UiArchiveNodeOld)}; template = new DataTemplate {DataType = typeof(UiNode)}; } FrameworkElementFactory stackPanel = new FrameworkElementFactory(typeof(StackPanel)); stackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); FrameworkElementFactory checkbox = new FrameworkElementFactory(typeof(CheckBox)); checkbox.SetValue(ToggleButton.IsCheckedProperty, new Binding("IsChecked") {Mode = BindingMode.TwoWay}); checkbox.SetValue(ToggleButton.IsThreeStateProperty, true); stackPanel.AppendChild(checkbox); 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(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("Name")); textBlock.SetValue(MarginProperty, new Thickness(3)); stackPanel.AppendChild(textBlock); template.VisualTree = stackPanel; return template; }
public BuildButtonFactory() { Title = "Build Button Factory"; // Button ��ü�� ���� ControlTemplate�� ���� // ��Ʈ���� ������ ������ ���Ѵ�. ControlTemplate template = new ControlTemplate(typeof(Button)); // ������Ʈ���� ����, ������Ʈ�� ������Ƽ�� ��ȭ�� ����� �� ���� �����ϴ� Ʈ���� ���� // Border Ŭ������ ���� FrameworkElementFactory�� ���� 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); // ContentPresenter Ŭ������ ���� FrameworkElementFactory�� ���� FrameworkElementFactory factoryContent = new FrameworkElementFactory(typeof(ContentPresenter)); // ���߿� �����ϱ� ���� �̸��� ���� factoryContent.Name = "content"; // �� ���� ContentPresenter ������Ƽ�� Button ������Ƽ�� ���ε� factoryContent.SetValue(ContentPresenter.ContentProperty, new TemplateBindingExtension(Button.ContentProperty)); // ��ư�� Padding�� ����Ʈ�� Margin��! factoryContent.SetValue(ContentPresenter.MarginProperty, new TemplateBindingExtension(Button.PaddingProperty)); // ContentPresenter�� Border�� �ڽ����� ���� factoryBorder.AppendChild(factoryContent); // Border�� ���־� Ʈ���� ��Ʈ ������Ʈ�� ���� template.VisualTree = factoryBorder; // IsMouseOver�� true�� �ɶ��� Trigger�� ���� // Trigger - ���Ǻ� �۾��� �����Ѵ�. Trigger trig = new Trigger(); trig.Property = UIElement.IsMouseOverProperty; trig.Value = true; // �� Ʈ���ſ� ������ Setter�� ���� // "Border" ������Ʈ�� CornerRadius ������Ƽ�� ���� Setter set = new Setter(); set.Property = Border.CornerRadiusProperty; set.Value = new CornerRadius(24); set.TargetName = "border"; // �տ��� ���� �̸��� ����( Trigger �۾��� �Ҷ��� Ÿ���� �� ) // Trigger�� Setters �÷��ǿ� Setter�� �߰� trig.Setters.Add(set); // ����� ������� FontStyle�� �����Ű�� Setter�� ���� // (��ư�� ������Ƽ�̹Ƿ� TargetName�� ���ʿ���) set = new Setter(); set.Property = Control.FontStyleProperty; set.Value = FontStyles.Italic; // ���� ���� �������, �� Setter�� Ʈ������ Setter �÷��� trig.Setters.Add(set); // Ʈ���Ÿ� ���ø��� �߰� template.Triggers.Add(trig); // ����� ������� IsPressed�� ���� Ʈ���Ÿ� ���� trig = new Trigger(); trig.Property = Button.IsPressedProperty; trig.Value = true; set = new Setter(); set.Property = Border.BackgroundProperty; set.Value = SystemColors.ControlDarkBrush; set.TargetName = "border"; // Trigger�� Setters �÷��ǿ� Setter�� �߰� trig.Setters.Add(set); // Ʈ���Ÿ� ���ø��� �߰� template.Triggers.Add(trig); // ���������� Button�� ���� 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; }
/// <summary> /// Set the Style of the bubbleImage /// </summary> public void SetStyle() { FrameworkElementFactory bubbleImage = new FrameworkElementFactory(typeof(Image)); String noteValue = Note.Duration.ToString(); int offset = GlobalVariables.ManipulationGrid.ElementAtOrDefault(Note.Position + 2); double betweenStave = (350 - offset) * (SessionVM.SessionSVI.ActualHeight / 1080); if (SVItem.Center.Y < betweenStave) { if (Note.Flat) bubbleImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/Notes/black/" + noteValue + "_bemol.png", UriKind.Relative))); else if (Note.Sharp) bubbleImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/Notes/black/" + noteValue + "_diese.png", UriKind.Relative))); else bubbleImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/Notes/black/" + noteValue + ".png", UriKind.Relative))); } else { if (Note.Flat) bubbleImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/Notes/white/" + noteValue + "_bemol.png", UriKind.Relative))); else if (Note.Sharp) bubbleImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/Notes/white/" + noteValue + "_diese.png", UriKind.Relative))); else bubbleImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/Notes/white/" + noteValue + ".png", UriKind.Relative))); } bubbleImage.SetValue(Image.IsHitTestVisibleProperty, false); bubbleImage.SetValue(Image.WidthProperty, (125.0 / 1920.0) * SessionVM.Grid.ActualWidth); bubbleImage.SetValue(Image.HeightProperty, (260.0 / 1080.0) * SessionVM.Grid.ActualHeight); FrameworkElementFactory touchZone = new FrameworkElementFactory(typeof(Ellipse)); //touchZone.SetValue(Ellipse.OpacityProperty, 0.3); touchZone.SetValue(Ellipse.FillProperty, Brushes.Transparent); touchZone.SetValue(Ellipse.WidthProperty, (47.0 / 1920.0) * SessionVM.Grid.ActualWidth); touchZone.SetValue(Ellipse.HeightProperty, (40.0 / 1080.0) * SessionVM.Grid.ActualHeight); FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid)); grid.AppendChild(bubbleImage); grid.AppendChild(touchZone); ControlTemplate ct = new ControlTemplate(typeof(ScatterViewItem)); ct.VisualTree = grid; Style bubbleStyle = new Style(typeof(ScatterViewItem)); bubbleStyle.Setters.Add(new Setter(ScatterViewItem.TemplateProperty, ct)); SVItem.Style = bubbleStyle; }
private static DataTemplate CreateDefaultEffectDataTemplate(UIElement target, BitmapImage effectIcon, string effectText, string destinationText) { if (!GetUseDefaultEffectDataTemplate(target)) { return null; } // Add icon var imageFactory = new FrameworkElementFactory(typeof(Image)); imageFactory.SetValue(Image.SourceProperty, effectIcon); imageFactory.SetValue(FrameworkElement.HeightProperty, 12.0); imageFactory.SetValue(FrameworkElement.WidthProperty, 12.0); imageFactory.SetValue(FrameworkElement.MarginProperty, new Thickness(0.0, 0.0, 3.0, 0.0)); // Add effect text var effectTextBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); effectTextBlockFactory.SetValue(TextBlock.TextProperty, effectText); effectTextBlockFactory.SetValue(TextBlock.FontSizeProperty, 11.0); effectTextBlockFactory.SetValue(TextBlock.ForegroundProperty, Brushes.Blue); // Add destination text var destinationTextBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); destinationTextBlockFactory.SetValue(TextBlock.TextProperty, destinationText); destinationTextBlockFactory.SetValue(TextBlock.FontSizeProperty, 11.0); destinationTextBlockFactory.SetValue(TextBlock.ForegroundProperty, Brushes.DarkBlue); destinationTextBlockFactory.SetValue(TextBlock.MarginProperty, new Thickness(3, 0, 0, 0)); destinationTextBlockFactory.SetValue(TextBlock.FontWeightProperty, FontWeights.DemiBold); // Create containing panel var stackPanelFactory = new FrameworkElementFactory(typeof(StackPanel)); stackPanelFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); stackPanelFactory.SetValue(FrameworkElement.MarginProperty, new Thickness(2.0)); stackPanelFactory.AppendChild(imageFactory); stackPanelFactory.AppendChild(effectTextBlockFactory); stackPanelFactory.AppendChild(destinationTextBlockFactory); // Add border var borderFactory = new FrameworkElementFactory(typeof(Border)); var stopCollection = new GradientStopCollection { new GradientStop(Colors.White, 0.0), new GradientStop(Colors.AliceBlue, 1.0) }; var gradientBrush = new LinearGradientBrush(stopCollection) { StartPoint = new Point(0, 0), EndPoint = new Point(0, 1) }; borderFactory.SetValue(Panel.BackgroundProperty, gradientBrush); borderFactory.SetValue(Border.BorderBrushProperty, Brushes.DimGray); borderFactory.SetValue(Border.CornerRadiusProperty, new CornerRadius(3.0)); borderFactory.SetValue(Border.BorderThicknessProperty, new Thickness(1.0)); borderFactory.AppendChild(stackPanelFactory); // Finally add content to template var template = new DataTemplate(); template.VisualTree = borderFactory; return template; }
private static ControlTemplate CreateDefaultErrorTemplate() { ControlTemplate defaultTemplate = new ControlTemplate(typeof(Control)); //<Border BorderThickness="1" BorderBrush="Red"> // <AdornedElementPlaceholder/> //</Border> FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border), "Border"); border.SetValue(Border.BorderBrushProperty, Brushes.Red); border.SetValue(Border.BorderThicknessProperty, new Thickness(1)); FrameworkElementFactory adornedElementPlaceHolder = new FrameworkElementFactory(typeof(AdornedElementPlaceholder), "Placeholder"); border.AppendChild(adornedElementPlaceHolder); defaultTemplate.VisualTree = border; defaultTemplate.Seal(); return defaultTemplate; }