本文整理汇总了C#中System.Windows.Setter类的典型用法代码示例。如果您正苦于以下问题:C# Setter类的具体用法?C# Setter怎么用?C# Setter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Setter类属于System.Windows命名空间,在下文中一共展示了Setter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ButtonBarControl
public ButtonBarControl(WebcamControl element)
{
InitializeComponent();
this.parent = element;
this.Name = "buttonBar";
int i;
buttons=new Button[numberOfButtons];
double buttonSpace = parent.WebcamImage.ActualWidth / numberOfButtons;
Style style = new Style(typeof(Button));
style.Setters.Add(new Setter { Property = OverridesDefaultStyleProperty, Value = true });
Setter templateSetter = new Setter();
templateSetter.Property = TemplateProperty;
ControlTemplate controlTemplate = new ControlTemplate(typeof(Button));
FrameworkElementFactory fact = new FrameworkElementFactory(typeof(Border));
controlTemplate.VisualTree = fact;
fact.Name = "Border";
//fact.SetValue(Border.BorderThicknessProperty, new Thickness(1));
//fact.SetValue(Border.CornerRadiusProperty, new CornerRadius(2));
fact.SetValue(Border.BackgroundProperty,new TemplateBindingExtension(Button.BackgroundProperty));
//fact.SetValue(Border.BorderBrushProperty, Brushes.Aquamarine);
Trigger triggerIsMouseOver = new Trigger { Property = Border.IsMouseOverProperty, Value = true };
Binding b = new Binding();
b.RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent);
b.Path = new PropertyPath(Button.BorderBrushProperty);
Setter setter = new Setter(Border.BackgroundProperty, b, "Border");
triggerIsMouseOver.Setters.Add(setter);
controlTemplate.Triggers.Add(triggerIsMouseOver);
templateSetter.Value = controlTemplate;
style.Setters.Add(templateSetter);
for (i = 0; i < numberOfButtons; i++)
{
buttons[i] = new Button();
//buttons[i].Foreground = new ImageBrush(new BitmapImage(new Uri("test.png", UriKind.Relative)));
buttons[i].Style = style;
buttons[i].Background = new ImageBrush(new BitmapImage(new Uri((i+1)+"1.png", UriKind.Relative)));
buttons[i].BorderBrush = new ImageBrush(new BitmapImage(new Uri((i+1)+"2.png", UriKind.Relative)));
//buttons[i].Content = "Button" + i;
buttons[i].Width = (buttonSpace-0.1*buttonSpace);
buttons[i].Height = 100 - 20;
buttons[i].Margin = new Thickness(0.05*buttonSpace, 10, 0.05*buttonSpace, 0);
buttons[i].Click += new RoutedEventHandler(ButtonBar_Click);
buttonStack.Children.Add(buttons[i]);
}
}
示例2: StyleSelectionMenuItemList
public StyleSelectionMenuItemList()
{
ItemsSource = ItemsSource = AvailableStyles.Instance;
var checkableMenuItemStyle = new Style { TargetType = typeof(MenuItem) };
var headerBinding = new Binding();
var headerSetter = new Setter(HeaderProperty, headerBinding);
checkableMenuItemStyle.Setters.Add(headerSetter);
var isCheckableSetter = new Setter(IsCheckableProperty, true);
checkableMenuItemStyle.Setters.Add(isCheckableSetter);
ICommand command = new RelayCommand(SelectStyle);
var commandSetter = new Setter(CommandProperty, command);
checkableMenuItemStyle.Setters.Add(commandSetter);
var commandParamBinding = new Binding();
var commandParamSetter = new Setter(CommandParameterProperty, commandParamBinding);
checkableMenuItemStyle.Setters.Add(commandParamSetter);
var isCheckedMultiBinding = new MultiBinding { Converter = new MultiValueStringsMatchConverter(), Mode = BindingMode.OneWay };
isCheckedMultiBinding.Bindings.Add(new Binding { Mode = BindingMode.OneWay });
isCheckedMultiBinding.Bindings.Add(new Binding("SelectedStyle") { Source = AvailableStyles.Instance, Mode = BindingMode.OneWay });
var isCheckedSetter = new Setter(IsCheckedProperty, isCheckedMultiBinding);
checkableMenuItemStyle.Setters.Add(isCheckedSetter);
Resources.Add(typeof(MenuItem), checkableMenuItemStyle);
}
示例3: CreateTest
public void CreateTest ()
{
Setter s = new Setter (UIElement.OpacityProperty, 2.0);
Assert.AreEqual (UIElement.OpacityProperty, s.Property);
Assert.AreEqual (2.0, s.Value);
}
示例4: SelectStyle
public override Style SelectStyle(object item, DependencyObject container)
{
Style style = new Style {
TargetType = typeof(ListBoxItem)
};
Setter setter = new Setter {
Property = Control.BackgroundProperty
};
ListBox box = ItemsControl.ItemsControlFromItemContainer(container) as ListBox;
switch (box.ItemContainerGenerator.IndexFromContainer(container))
{
case 0:
setter.Value = Brushes.LightBlue;
break;
case 1:
setter.Value = Brushes.Green;
break;
default:
setter.Value = Brushes.SaddleBrown;
break;
}
style.Setters.Add(setter);
return style;
}
示例5: FindResource
object FindResource(object resourceKey)
{
// NOTE: This code depends on internal implementation details of WPF and
// might break in a future release of the platform. Use at your own risk!
var resourceReferenceExpression =
new DynamicResourceExtension(resourceKey).ProvideValue(null)
as Expression;
MethodInfo getValue = typeof(Expression).GetMethod(
"GetValue",
BindingFlags.Instance | BindingFlags.NonPublic);
object result = getValue.Invoke(
resourceReferenceExpression,
new object[] { this, DummyProperty });
// Either we do not have an inheritance context or the
// requested resource does not exist, so return null.
if (result == DependencyProperty.UnsetValue)
return null;
// The requested resource was found, so we will receive a
// DeferredResourceReference object as a result of calling
// GetValue. The only way to resolve that to the actual
// resource, without using reflection, is to have a Setter's
// Value property unwrap it for us.
var deferredResourceReference = result;
Setter setter = new Setter(DummyProperty, deferredResourceReference);
return setter.Value;
}
示例6: Window_Loaded
private void Window_Loaded(object sender, RoutedEventArgs e)
{
GridView myGridView = new GridView();
myGridView.AllowsColumnReorder = true;
//Collapse the header
Style collapsedHeaderStyle = new Style();
Setter collapsedHeaderSetter = new Setter();
collapsedHeaderSetter.Property = VisibilityProperty;
collapsedHeaderSetter.Value = Visibility.Collapsed;
collapsedHeaderStyle.Setters.Add(collapsedHeaderSetter);
myGridView.ColumnHeaderContainerStyle = collapsedHeaderStyle;
for (int i = 0; i < control.XSize; i++)
{
GridViewColumn col = new GridViewColumn();
col.DisplayMemberBinding = new Binding("Column[" + i.ToString() + "]");
col.Width = 30;
myGridView.Columns.Add(col);
}
listView.View = myGridView;
listView.DataContext = control.AgentCollection;
}
示例7: LabelTextBox
public LabelTextBox()
{
this.AcceptsReturn = true;
this.FontWeight = FontWeights.Bold;
this.BorderThickness = new Thickness(0);
Setter borderSetter = new Setter();
borderSetter.Property = TextBox.BorderThicknessProperty;
borderSetter.Value = new Thickness(0);
Trigger readOnlyTrigger = new Trigger();
readOnlyTrigger.Property = TextBox.IsReadOnlyProperty;
readOnlyTrigger.Value = true;
readOnlyTrigger.Setters.Add(borderSetter);
Setter borderFocusSetter = new Setter();
borderFocusSetter.Property = TextBox.BorderThicknessProperty;
borderFocusSetter.Value = new Thickness(0);
Trigger focusTrigger = new Trigger();
focusTrigger.Property = TextBox.IsFocusedProperty;
focusTrigger.Value = true;
focusTrigger.Setters.Add(borderFocusSetter);
Style style = new Style();
style.Triggers.Add(readOnlyTrigger);
style.Triggers.Add(focusTrigger);
this.Style = style;
this.SnapsToDevicePixels = true;
}
示例8: TestImplicitStyleRectangle_styleInRectangleDictionary
public void TestImplicitStyleRectangle_styleInRectangleDictionary ()
{
Style rectStyle = new Style { TargetType = typeof (Rectangle) };
Setter setter = new Setter (FrameworkElement.WidthProperty, 100.0);
rectStyle.Setters.Add (setter);
Rectangle r = new Rectangle ();
Assert.IsTrue (Double.IsNaN (r.Width), "1");
r.Resources.Add (typeof (Rectangle), rectStyle);
Assert.AreEqual (100.0, r.Width, "2");
CreateAsyncTest (r, () => {
Assert.AreEqual (100.0, r.Width, "3");
//setter.Value = 200.0;
//Assert.AreEqual (200.0, r.Width, "4");
rectStyle.Setters.Remove (setter);
Assert.AreEqual (100.0, r.Width, "5");
});
}
示例9: GetResourceDictionary
public ResourceDictionary GetResourceDictionary()
{
var dict = new ResourceDictionary
{
Source = new Uri(GetThemePath(UserSettingStorage.Instance.Theme), UriKind.Absolute)
};
Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
if (queryBoxStyle != null)
{
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStretch)));
}
Style resultItemStyle = dict["ItemTitleStyle"] as Style;
Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style;
Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style;
Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style;
if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null)
{
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont));
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle));
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight));
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStretch));
Setter[] setters = new Setter[] { fontFamily, fontStyle, fontWeight, fontStretch };
Array.ForEach(new Style[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
}
return dict;
}
示例10: ZoomableInlineAdornment
public ZoomableInlineAdornment(UIElement content, ITextView parent) {
_parent = parent;
Debug.Assert(parent is IInputElement);
Content = new Border { BorderThickness = new Thickness(1), Child = content, Focusable = true };
_zoom = 1.0; // config.GetConfig().Repl.InlineMedia.MaximizedZoom
_zoomStep = 0.25; // config.GetConfig().Repl.InlineMedia.ZoomStep
_minimizedZoom = 0.25; // config.GetConfig().Repl.InlineMedia.MinimizedZoom
_widthRatio = 0.67; // config.GetConfig().Repl.InlineMedia.WidthRatio
_heightRatio = 0.5; // config.GetConfig().Repl.InlineMedia.HeightRatio
_isResizing = false;
UpdateSize();
GotFocus += OnGotFocus;
LostFocus += OnLostFocus;
ContextMenu = MakeContextMenu();
var trigger = new Trigger { Property = Border.IsFocusedProperty, Value = true };
var setter = new Setter { Property = Border.BorderBrushProperty, Value = SystemColors.ActiveBorderBrush };
trigger.Setters.Add(setter);
var style = new Style();
style.Triggers.Add(trigger);
MyContent.Style = style;
}
示例11: TestImplicitStyleRectangle_multipleImplicitStylesInVisualTree
public void TestImplicitStyleRectangle_multipleImplicitStylesInVisualTree ()
{
Style rectStyle1 = new Style { TargetType = typeof (Rectangle) };
Setter setter = new Setter (FrameworkElement.WidthProperty, 100.0);
rectStyle1.Setters.Add (setter);
Style rectStyle2 = new Style { TargetType = typeof (Rectangle) };
setter = new Setter (FrameworkElement.HeightProperty, 100.0);
rectStyle2.Setters.Add (setter);
Rectangle r = new Rectangle ();
r.Resources.Add (typeof (Rectangle), rectStyle1);
Canvas c = new Canvas ();
c.Resources.Add (typeof (Rectangle), rectStyle2);
c.Children.Add (r);
Assert.IsTrue (Double.IsNaN (r.Height), "1");
CreateAsyncTest (c, () => {
Assert.AreEqual (100.0, r.Width, "2");
Assert.IsTrue (Double.IsNaN (r.Height), "3");
r.Resources.Remove (typeof (Rectangle));
Assert.AreEqual (100.0, r.Height, "4");
Assert.IsTrue (Double.IsNaN (r.Width), "5");
});
}
示例12: AlternatingListBoxBackground
public AlternatingListBoxBackground(Color color1, Color color2)
{
var setter = new Setter();
setter.Property = ListBoxItem.BackgroundProperty;
setter.Value = new SolidColorBrush(color1);
var trigger = new Trigger();
trigger.Property = ItemsControl.AlternationIndexProperty;
trigger.Value = 0;
trigger.Setters.Add(setter);
var setter2 = new Setter();
setter2.Property = ListBoxItem.BackgroundProperty;
setter2.Value = new SolidColorBrush(color2);
var trigger2 = new Trigger();
trigger2.Property = ItemsControl.AlternationIndexProperty;
trigger2.Value = 1;
trigger2.Setters.Add(setter2);
var listBoxStyle = new Style(typeof(ListBoxItem));
listBoxStyle.Triggers.Add(trigger);
listBoxStyle.Triggers.Add(trigger2);
_listBoxStyle = listBoxStyle;
}
示例13: CreateSetter
private static SetterBase CreateSetter(EntityFieldInfo fieldInfo, IDataService dataService, GenericDataListState state, bool? isLocked, FrameworkElement element)
{
Setter setter = new Setter();
setter.Property = ContentControl.ContentTemplateProperty;
setter.Value = DataControlTemplateBuilder.CreateTemplate(fieldInfo, dataService, state, isLocked,element);
return setter;
}
示例14: Defaults
public void Defaults ()
{
Setter s = new Setter ();
Assert.IsNull (s.Property, "Property");
Assert.IsNull (s.Value, "Value");
// SetterBase (can't be tested indivisually since the type has no visible ctor)
Assert.IsFalse (s.IsSealed, "IsSealed");
}
示例15: CopyTo
public void CopyTo(Setter[] array, int arrayIndex)
{
if (array == null)
{
throw new ArgumentNullException("array");
}
List.CopyTo(array, arrayIndex);
}