本文整理汇总了C#中System.Windows.FrameworkElementFactory类的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElementFactory类的具体用法?C# FrameworkElementFactory怎么用?C# FrameworkElementFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FrameworkElementFactory类属于System.Windows命名空间,在下文中一共展示了FrameworkElementFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateItemTemplate
private DataTemplate CreateItemTemplate()
{
var template = new DataTemplate();
template.VisualTree = new FrameworkElementFactory(typeof(StackPanel));
var txtBlock = new FrameworkElementFactory(typeof(TextBlock));
txtBlock.SetBinding(TextBlock.TextProperty, new Binding("Street1"));
template.VisualTree.AppendChild(txtBlock);
txtBlock = new FrameworkElementFactory(typeof(TextBlock));
txtBlock.SetBinding(TextBlock.TextProperty, new Binding("City"));
template.VisualTree.AppendChild(txtBlock);
var trigger = new MultiDataTrigger();
trigger.Conditions.Add(
new Condition(
new Binding("Cty"), //misspelling
"Tallahassee"
)
);
trigger.Conditions.Add(
new Condition(
new Binding("StateOrProvince"),
"Florida"
)
);
template.Triggers.Add(trigger);
return template;
}
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:34,代码来源:UIBoundToCustomerWithContentControlAndMultiTriggers.cs
示例2: EditableBlock
public static sw.FrameworkElementFactory EditableBlock(swd.RelativeSource relativeSource)
{
var factory = new sw.FrameworkElementFactory(typeof(EditableTextBlock));
var binding = new sw.Data.Binding { Path = TextPath, RelativeSource = relativeSource, Mode = swd.BindingMode.TwoWay, UpdateSourceTrigger = swd.UpdateSourceTrigger.PropertyChanged };
factory.SetBinding(EditableTextBlock.TextProperty, binding);
return factory;
}
示例3: CreateByViewType
public DataTemplate CreateByViewType(Type viewModelType, Type viewType)
{
var dt = new DataTemplate(viewModelType);
var factory = new FrameworkElementFactory(viewType);
dt.VisualTree = factory;
return dt;
}
示例4: ColorWheel
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));
}
示例5: ColorGridBox
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";
}
示例6: TextBlock
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;
}
示例7: ComboBoxBackend
//private static readonly DataTemplate DefaultTemplate;
static ComboBoxBackend()
{
if (System.Windows.Application.Current.Resources.MergedDictionaries.Count == 0 ||
!System.Windows.Application.Current.Resources.MergedDictionaries.Any(x => x.Contains(typeof(ExComboBox))))
{
var factory = new FrameworkElementFactory(typeof(WindowsSeparator));
factory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
var sepTemplate = new ControlTemplate(typeof(ComboBoxItem));
sepTemplate.VisualTree = factory;
DataTrigger trigger = new DataTrigger();
trigger.Binding = new Binding(".[1]") { Converter = new TypeToStringConverter() };
trigger.Value = typeof(ItemSeparator).Name;
trigger.Setters.Add(new Setter(Control.TemplateProperty, sepTemplate));
trigger.Setters.Add(new Setter(UIElement.IsEnabledProperty, false));
ContainerStyle = new Style(typeof(ComboBoxItem));
ContainerStyle.Triggers.Add(trigger);
}
else
{
ContainerStyle = null;
}
}
示例8: GenerateMetaColumns
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);
}
}
}
示例9: 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;
}
示例10: CreateOnOffServiceScheduleButtonTemplate
public FrameworkElementFactory CreateOnOffServiceScheduleButtonTemplate()
{
FrameworkElementFactory buttonTemplate = new FrameworkElementFactory(typeof (CheckBox));
buttonTemplate.SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsOn")
{
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
});
buttonTemplate.AddHandler(
ToggleButton.CheckedEvent,
new RoutedEventHandler((o, e) =>
{
DataGridServiceScheduleView dataGridServiceScheduleView =
((FrameworkElement) o).DataContext as DataGridServiceScheduleView;
if (dataGridServiceScheduleView != null)
{
dataGridServiceScheduleView.IsOn = true.ToString();
}
}));
buttonTemplate.AddHandler(
ToggleButton.UncheckedEvent,
new RoutedEventHandler((o, e) =>
{
DataGridServiceScheduleView dataGridServiceScheduleView =
((FrameworkElement) o).DataContext as DataGridServiceScheduleView;
if (dataGridServiceScheduleView != null)
{
dataGridServiceScheduleView.IsOn = false.ToString();
}
}));
return buttonTemplate;
}
示例11: CreateDefaultTemplate
internal static DataTemplate CreateDefaultTemplate()
{
var dataTemplate = new DataTemplate();
var factory = new FrameworkElementFactory(typeof(ContentPresenter));
dataTemplate.VisualTree = factory;
return dataTemplate;
}
示例12: KernelOnComponentRegistered
private void KernelOnComponentRegistered(string key, IHandler handler)
{
Type implementation = handler.ComponentModel.Implementation;
if (implementation.Namespace == null ||
!implementation.Namespace.EndsWith("ViewModels"))
{
return;
}
var viewTypeName = implementation.Namespace.Replace("ViewModels", "Views") + "." +
implementation.Name.Replace("ViewModel", "View");
var qualifiedViewTypeName = implementation.AssemblyQualifiedName.Replace(implementation.FullName, viewTypeName);
Type viewType = Type.GetType(qualifiedViewTypeName, false);
if (viewType == null)
{
throw new InvalidOperationException();
}
var dt = new DataTemplate {DataType = viewType};
var viewFactory = new FrameworkElementFactory(viewType);
dt.VisualTree = viewFactory;
_resources.Add(new DataTemplateKey(implementation), dt);
}
示例13: TextureManager
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;
}
示例14: Convert
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var template = value as Xamarin.Forms.DataTemplate;
var uc = new FrameworkElementFactory(typeof(UserControl));
if (template != null)
{
uc.SetBinding(UserControl.ContentProperty, new MultiBinding
{
Converter = new CellToViewConverter(),
Bindings =
{
new Binding(),
new Binding { Source = template }
}
});
}
else
{
uc.SetBinding(UserControl.ContentProperty, new Binding
{
Converter = new ModelToViewConverter()
});
}
return new DataTemplate { VisualTree = uc };
}
示例15: 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;
}