本文整理汇总了C#中System.Windows.FrameworkElementFactory.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElementFactory.SetValue方法的具体用法?C# FrameworkElementFactory.SetValue怎么用?C# FrameworkElementFactory.SetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElementFactory
的用法示例。
在下文中一共展示了FrameworkElementFactory.SetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainWindowViewModel
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();
}
示例2: SelectTemplate
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;
}
示例3: 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;
}
示例4: 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;
}
示例5: ShowResourcesGained_DataContextChanged
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;
}
}
示例6: 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;
}
示例7: ApplyAutogeneratedColumnAttributes
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 };
}
}
示例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: 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
示例10: 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;
}
示例11: 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));
}
示例12: button1_Click
// 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: AddButtonColumn
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);
}
示例14: 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
};
}
示例15: GetFactory
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;
}