本文整理汇总了C#中System.Windows.FrameworkElementFactory.AppendChild方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElementFactory.AppendChild方法的具体用法?C# FrameworkElementFactory.AppendChild怎么用?C# FrameworkElementFactory.AppendChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElementFactory
的用法示例。
在下文中一共展示了FrameworkElementFactory.AppendChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTemplate
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;
}
示例2: SelectTemplate
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 };
}
开发者ID:pedone,项目名称:DecisionTableAnalizer,代码行数:25,代码来源:ContradictionSelectionHeaderTemplateSelector.cs
示例3: ListColorsEvenElegantlier
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;
}
示例4: SelectFolderDesigner
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;
}
示例5: ItemTemplate
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;
}
示例6: ItemTemplate
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;
}
示例7: BuildDataTemplate
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
};
}
示例8: ListColorsEvenElegantlier
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;
}
示例9: setBackgroundImage
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;
}
示例10: TreeGridViewColumn
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;
}
示例11: GetTreeHeaderDataTemplate
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;
}
示例12: CreateBoundColumnTemplate
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;
}
示例13: DataGridDbObjectColumn
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;
}
示例14: ImageHeader
/// <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;
}
示例15: UserDataEditor
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;
}