當前位置: 首頁>>代碼示例>>C#>>正文


C# Xaml.Style類代碼示例

本文整理匯總了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;
		}
開發者ID:Costo,項目名稱:Xamarin.Forms,代碼行數:33,代碼來源:WindowsResourcesProvider.cs

示例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;
                }
            }
        }
開發者ID:sdao,項目名稱:TuneOut,代碼行數:29,代碼來源:AppBarToggleButton.cs

示例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));
             }
         }
     }
 }
開發者ID:ckc,項目名稱:WinApp,代碼行數:30,代碼來源:Scenario2_CustomizeColor.xaml.cs

示例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;
        }
開發者ID:fernandoescolar,項目名稱:myweather,代碼行數:34,代碼來源:StyleStaticResourceConverter.cs

示例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;
 }
開發者ID:aurora-lzzp,項目名稱:com.aurora.aumusic,代碼行數:31,代碼來源:ListViewItemStyleSelector.cs

示例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);
     }
 }
開發者ID:JanJoris,項目名稱:Expander,代碼行數:8,代碼來源:ItemsControlHelper.cs

示例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);
     }
 }
開發者ID:JanJoris,項目名稱:Expander,代碼行數:8,代碼來源:HeaderedItemsControl.cs

示例8: CreateGrid

        public static Grid CreateGrid(Style s, Grid g)
        {
            Grid newG = new Grid();
            newG.Style = s;

            g.Children.Add(newG);

            return newG;
        }
開發者ID:BlowingPolarBears,項目名稱:MagicPolarBear,代碼行數:9,代碼來源:CreateXAMLObj.cs

示例9: AdaptiveGridView

        public AdaptiveGridView()
        {
            if (ItemContainerStyle == null)
                ItemContainerStyle = new Style(typeof(GridViewItem));

            ItemContainerStyle.Setters.Add(new Setter(HorizontalContentAlignmentProperty, HorizontalAlignment.Stretch));
            
            Loaded += AdaptiveGridView_Loaded;
        }
開發者ID:Flogex,項目名稱:Vertretungsplan,代碼行數:9,代碼來源:AdaptiveGridView.cs

示例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();
        }
開發者ID:ronlemire2,項目名稱:UWP-Testers,代碼行數:9,代碼來源:SharedBrushWithStylePage.xaml.cs

示例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;
        }
開發者ID:BlowingPolarBears,項目名稱:MagicPolarBear,代碼行數:10,代碼來源:CreateXAMLObj.cs

示例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;
        }
開發者ID:BlowingPolarBears,項目名稱:MagicPolarBear,代碼行數:11,代碼來源:CreateXAMLObj.cs

示例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;
        }
開發者ID:stephgou,項目名稱:Thot,代碼行數:13,代碼來源:AlternateRowStyleSelector.cs

示例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;
        }
開發者ID:BlowingPolarBears,項目名稱:MagicPolarBear,代碼行數:13,代碼來源:CreateXAMLObj.cs

示例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;
 }
開發者ID:RedSafi-UX,項目名稱:SugarUIEnhancedControls,代碼行數:13,代碼來源:DateTimeHelper.cs


注:本文中的Windows.UI.Xaml.Style類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。