本文整理匯總了C#中Windows.UI.Xaml.Style類的典型用法代碼示例。如果您正苦於以下問題:C# Style類的具體用法?C# Style怎麽用?C# Style使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Style類屬於Windows.UI.Xaml命名空間,在下文中一共展示了Style類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetStyle
Style GetStyle(object nativeKey)
{
var style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources[nativeKey];
var formsStyle = new Style(typeof(Label));
foreach (SetterBase b in style.Setters)
{
var setter = b as Windows.UI.Xaml.Setter;
if (setter == null)
continue;
// TODO: Need to implement a stealth pass-through for things we don't support
try
{
if (setter.Property == TextBlock.FontSizeProperty)
formsStyle.Setters.Add(Label.FontSizeProperty, setter.Value);
else if (setter.Property == TextBlock.FontFamilyProperty)
formsStyle.Setters.Add(Label.FontFamilyProperty, setter.Value);
else if (setter.Property == TextBlock.FontWeightProperty)
formsStyle.Setters.Add(Label.FontAttributesProperty, ToAttributes(Convert.ToUInt16(setter.Value)));
else if (setter.Property == TextBlock.TextWrappingProperty)
formsStyle.Setters.Add(Label.LineBreakModeProperty, ToLineBreakMode((TextWrapping)setter.Value));
}
catch (NotImplementedException)
{
// see https://bugzilla.xamarin.com/show_bug.cgi?id=33135
// WinRT implementation of Windows.UI.Xaml.Setter.get_Value is not implemented.
}
}
return formsStyle;
}
示例2: IsCheckedChanged
private void IsCheckedChanged()
{
if (IsChecked)
{
if (CheckedStyle != null)
{
_style = Style;
Style = CheckedStyle;
}
if (CheckedAutomationName != null)
{
_automationName = AutomationName;
AutomationName = CheckedAutomationName;
}
}
else
{
if (CheckedStyle != null)
{
Style = _style;
}
if (CheckedAutomationName != null)
{
AutomationName = _automationName;
}
}
}
示例3: ColorButtons
/// <summary>
/// This method will change the style of each AppBarButton to use a green foreground color
/// </summary>
/// <param name="panel"></param>
private void ColorButtons(StackPanel panel)
{
int count = 0;
foreach (var item in panel.Children)
{
// For AppBarButton, change the style
if (item.GetType() == typeof(AppBarButton))
{
if (count == 0)
{
originalButtonStyle = ((AppBarButton)item).Style;
}
((AppBarButton)item).Style = rootPage.Resources["GreenAppBarButtonStyle"] as Style;
count++;
}
else
{
// For AppBarSeparator(s), just change the foreground color
if (item.GetType() == typeof(AppBarSeparator))
{
originalSeparatorBrush = ((AppBarSeparator)item).Foreground;
((AppBarSeparator)item).Foreground = new SolidColorBrush(Color.FromArgb(255, 90, 200, 90));
}
}
}
}
示例4: Convert
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value == null) return null;
var resourceKey = value.ToString();
var resource = Application.Current.Resources[resourceKey] as Style;
if (resource != null)
{
var style = new Style();
style.BasedOn = resource.BasedOn;
style.TargetType = resource.TargetType;
foreach (var setter in resource.Setters)
{
var s = setter as Setter;
if (s != null)
{
var g = s.Value as PathGeometry;
if (g != null)
{
style.Setters.Add(new Setter(s.Property, CloneDeep(g)));
}
else
{
style.Setters.Add(new Setter(s.Property, s.Value));
}
}
}
return style;
}
return null;
}
示例5: SelectStyleCore
protected override Style SelectStyleCore(object item,
DependencyObject container)
{
Style st = new Style();
st.TargetType = typeof(ListViewItem);
Setter backGroundSetter = new Setter();
backGroundSetter.Property = ListViewItem.BackgroundProperty;
ListView listView =
ItemsControl.ItemsControlFromItemContainer(container)
as ListView;
int index =
listView.IndexFromContainer(container);
if (index % 2 == 0)
{
backGroundSetter.Value = (Color)Application.Current.Resources["SystemBackgroundAltHighColor"];
}
else
{
backGroundSetter.Value = (Color)Application.Current.Resources["SystemAltHighColor"];
}
st.Setters.Add(backGroundSetter);
Setter paddingSetter = new Setter();
paddingSetter.Property = ListViewItem.PaddingProperty;
paddingSetter.Value = 0;
st.Setters.Add(paddingSetter);
Setter alignSetter = new Setter();
alignSetter.Property = ListViewItem.HorizontalContentAlignmentProperty;
alignSetter.Value = "Stretch";
st.Setters.Add(alignSetter);
return st;
}
示例6: PrepareContainerForItemOverride
internal static void PrepareContainerForItemOverride(DependencyObject element, Style parentItemContainerStyle)
{
var control = element as Control;
if (parentItemContainerStyle != null && control != null && control.Style == null)
{
control.SetValue(FrameworkElement.StyleProperty, parentItemContainerStyle);
}
}
示例7: PreparePrepareHeaderedItemsControlContainerForItemOverride
internal static void PreparePrepareHeaderedItemsControlContainerForItemOverride(DependencyObject element, object item, ItemsControl parent, Style parentItemContainerStyle)
{
var headeredItemsControl = element as HeaderedItemsControl;
if (headeredItemsControl != null)
{
PreparePrepareHeaderedItemsControlContainer(headeredItemsControl, item, parent, parentItemContainerStyle);
}
}
示例8: CreateGrid
public static Grid CreateGrid(Style s, Grid g)
{
Grid newG = new Grid();
newG.Style = s;
g.Children.Add(newG);
return newG;
}
示例9: AdaptiveGridView
public AdaptiveGridView()
{
if (ItemContainerStyle == null)
ItemContainerStyle = new Style(typeof(GridViewItem));
ItemContainerStyle.Setters.Add(new Setter(HorizontalContentAlignmentProperty, HorizontalAlignment.Stretch));
Loaded += AdaptiveGridView_Loaded;
}
示例10: SharedBrushWithStylePage
public SharedBrushWithStylePage() {
// Taken from Petzold book but never tested. Needs another setter for LinearGradientBrush.
Style style = new Style(typeof(TextBlock));
style.Setters.Add(new Setter { Property = TextBlock.FontSizeProperty, Value = 96 });
style.Setters.Add(new Setter { Property = TextBlock.FontFamilyProperty, Value = "Times New Roman" });
this.Resources.Add("rainbowStyle", style);
this.InitializeComponent();
}
示例11: CreateTextBlock
public static TextBlock CreateTextBlock(string txt, Style s, Grid g)
{
TextBlock tB = new TextBlock();
tB.Text = txt;
tB.Style = s;
g.Children.Add(tB);
return tB;
}
示例12: CreateTextBox
public static TextBox CreateTextBox(string name,Style s, Grid g)
{
TextBox tB = new TextBox();
tB.Name = name;
tB.Style = s;
g.Children.Add(tB);
return tB;
}
示例13: SelectStyleCore
protected override Style SelectStyleCore(object item, DependencyObject container)
{
SolidColorBrush highlight;
if (_index % 2 == 0)
highlight = new SolidColorBrush(Colors.White);
else
highlight = new SolidColorBrush(Colors.CornflowerBlue);
_index++;
Style style = new Style(container.GetType());
style.Setters.Add(new Setter(Control.BackgroundProperty, highlight));
return style;
}
示例14: CreateButton
public static Button CreateButton(string name, Style s, string content, RoutedEventHandler button_Click, Grid g)
{
Button button = new Button();
button.Name = name + "_Button";
button.Style = s;
button.Content = content;
button.Click += button_Click;
g.Children.Add(button);
return button;
}
示例15: GetButton
public static Button GetButton(string content, Style style, RoutedEventHandler callback, object tag = null)
{
Button btn = new Button();
btn.Content = content;
btn.Margin = new Thickness(0, 0, 0, 0);
btn.Tag = tag;
btn.Loaded += btn_Loaded;
if (style != null)
btn.Style = style;
if (callback != null)
btn.Click += callback;
return btn;
}