本文整理汇总了C#中ResourceDictionary.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceDictionary.Add方法的具体用法?C# ResourceDictionary.Add怎么用?C# ResourceDictionary.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResourceDictionary
的用法示例。
在下文中一共展示了ResourceDictionary.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyPage
public MyPage()
{
Resources = new ResourceDictionary();
Resources.Add("primaryGreen", Color.FromHex("91CA47"));
Resources.Add("primaryDarkGreen", Color.FromHex("6FA22E"));
var nav = new NavigationPage(new AAloggerUpSwipeView());
nav.BarTextColor = Color.Blue;
MainPage = nav;
}
示例2: App
public App()
{
#region Style
var contentPageStyle = new Style(typeof(ContentPage))
{
Setters = {
new Setter { Property = ContentPage.BackgroundColorProperty, Value = Constants.palette.primary },
}
};
var labelStyle = new Style(typeof(Label))
{
Setters = {
new Setter { Property = Label.TextColorProperty, Value = Constants.palette.primary_text },
}
};
var editorStyle = new Style(typeof(Editor))
{
Setters = {
new Setter { Property = Editor.TextColorProperty, Value = Constants.palette.primary_text },
new Setter { Property = Editor.BackgroundColorProperty, Value = Constants.palette.primary_light },
}
};
var buttonStyle = new Style(typeof(Button))
{
Setters = {
new Setter { Property = Button.TextColorProperty, Value = Constants.palette.primary_text },
new Setter { Property = Button.BackgroundColorProperty, Value = Constants.palette.primary_light },
}
};
var switchStyle = new Style(typeof(Switch))
{
Setters = {
new Setter { Property = Switch.BackgroundColorProperty, Value = Constants.palette.primary_light },
}
};
Resources = new ResourceDictionary();
Resources.Add("contentPageStyle", contentPageStyle);
Resources.Add("labelStyle", labelStyle);
Resources.Add("editorStyle", editorStyle);
#endregion
// The root page of your application
mainPage = new NavigationPage(new mainPage())
{
BarBackgroundColor = Constants.palette.primary_dark,
BarTextColor = Constants.palette.icons,
Title = "VOCAB MASTER",
};
MainPage = mainPage;
}
示例3: App
public App ()
{
Resources = new ResourceDictionary ();
Resources.Add ("primaryGreen", Color.FromHex("91CA47"));
Resources.Add ("primaryDarkGreen", Color.FromHex ("6FA22E"));
var nav = new NavigationPage (new TodoListPage ());
nav.BarBackgroundColor = (Color)App.Current.Resources["primaryGreen"];
nav.BarTextColor = Color.White;
MainPage = nav;
}
示例4: SimpleTriggerPage
public SimpleTriggerPage ()
{
var t = new Trigger (typeof(Entry));
t.Property = Entry.IsFocusedProperty;
t.Value = true;
t.Setters.Add (new Setter {Property = Entry.ScaleProperty, Value = 1.5 } );
var s = new Style (typeof(Entry));
s.Setters.Add (new Setter { Property = AnchorXProperty, Value = 0} );
s.Triggers.Add (t);
Resources = new ResourceDictionary ();
Resources.Add (s);
Padding = new Thickness (20, 50, 120, 0);
Content = new StackLayout {
Spacing = 20,
Children = {
new Entry { Placeholder = "enter name" },
new Entry { Placeholder = "enter address" },
new Entry { Placeholder = "enter city and name" },
}
};
}
示例5: CustomEasingSwellPage
public CustomEasingSwellPage()
{
Resources = new ResourceDictionary();
Resources.Add("customEase", new Easing(t => -6 * t * t + 7 * t));
InitializeComponent();
}
示例6: ShallowCopy
/// <summary>
/// Makes a shallow copy of the specified ResourceDictionary.
/// </summary>
/// <param name="dictionary">ResourceDictionary to copy.</param>
/// <returns>Copied ResourceDictionary.</returns>
public static ResourceDictionary ShallowCopy(this ResourceDictionary dictionary)
{
ResourceDictionary clone = new ResourceDictionary();
foreach (object key in dictionary.Keys)
{
clone.Add(key, dictionary[key]);
}
return clone;
}
示例7: App
public App()
{
// The root page of your application
MainPage = new NavigationPage(new Inicio());
// Amostra grátis de Styles
var btnStyle = new Style(typeof(Button));
btnStyle.Setters.Add(new Setter() { Property = Button.BackgroundColorProperty, Value = Color.Red });
btnStyle.Setters.Add(new Setter() { Property = Button.TextColorProperty, Value = Color.White });
Resources = new ResourceDictionary();
Resources.Add(btnStyle);
}
示例8: ImplicitStylesPageCS
public ImplicitStylesPageCS ()
{
var entryStyle = new Style (typeof(Entry)) {
Setters = {
new Setter {
Property = View.HorizontalOptionsProperty,
Value = LayoutOptions.Fill
},
new Setter {
Property = View.VerticalOptionsProperty,
Value = LayoutOptions.CenterAndExpand
},
new Setter {
Property = VisualElement.BackgroundColorProperty,
Value = Color.Yellow
},
new Setter {
Property = Entry.FontAttributesProperty,
Value = FontAttributes.Italic
},
new Setter {
Property = Entry.TextColorProperty,
Value = Color.Blue
}
}
};
Title = "Implicit";
Icon = "csharp.png";
Padding = new Thickness (0, 20, 0, 0);
Resources = new ResourceDictionary ();
Resources.Add (entryStyle);
Content = new StackLayout {
Children = {
new Entry { Text = "These entries" },
new Entry { Text = "are demonstrating" },
new Entry { Text = "implicit styles," },
new Entry { Text = "and an implicit style override", BackgroundColor = Color.Lime, TextColor = Color.Red },
new CustomEntry { Text = "Subclassed Entry is not receiving the style" }
}
};
}
示例9: Clone
private static void Clone(ResourceDictionary source, ResourceDictionary target)
{
foreach (var resourceKeyValue in source)
{
target.Add(resourceKeyValue.Key, resourceKeyValue.Value);
}
foreach (var dictionary in source.MergedDictionaries)
{
var clone = new ResourceDictionary();
Clone(dictionary, clone);
target.MergedDictionaries.Add(clone);
}
foreach (var dictionaryKeyValue in source.ThemeDictionaries)
{
var clone = new ResourceDictionary();
Clone((ResourceDictionary)dictionaryKeyValue.Value, clone);
target.ThemeDictionaries.Add(dictionaryKeyValue.Key, clone);
}
}
示例10: RenameResources
public void RenameResources() {
if (resourceManagerType == null && componentResourceManagerType == null)
return;
var rsrcDict = new ResourceDictionary();
foreach (var resource in module.Resources)
rsrcDict.Add(resource);
if (module.Assembly != null)
Rename(rsrcDict, "", module.Assembly.Name + ".g");
foreach (var type in callsResourceManager.Keys)
Rename(rsrcDict, type);
if (rsrcDict.Count != 0) {
foreach (var type in module.GetTypes()) {
if (rsrcDict.Count == 0)
break;
if (!IsWinFormType(type))
continue;
Rename(rsrcDict, type);
}
}
if (rsrcDict.Count != 0) {
foreach (var type in module.GetTypes()) {
if (rsrcDict.Count == 0)
break;
Rename(rsrcDict, type);
}
}
if (rsrcDict.Count != 0)
Logger.e("Couldn't restore all renamed resource names");
}
示例11: SetStyles
private void SetStyles()
{
Resources = new ResourceDictionary ();
var contentStyle = new Style (typeof(ContentPage)) {
Setters = {
new Setter {
Property = ContentPage.BackgroundColorProperty,
Value = Color.White
}
}
};
Resources.Add (contentStyle);
var entryStyle = new Style (typeof(Entry)) {
Setters = {
new Setter {
Property = Entry.BackgroundColorProperty,
Value = Color.FromHex("EEEEEE")
},
new Setter {
Property = Entry.TextColorProperty,
Value = Color.FromHex("333333")
},
new Setter {
Property = Entry.HorizontalOptionsProperty,
Value = LayoutOptions.FillAndExpand
},
new Setter {
Property = Entry.VerticalOptionsProperty,
Value = LayoutOptions.CenterAndExpand
}
}
};
Resources.Add (entryStyle);
var editorStyle = new Style (typeof(Editor)) {
Setters = {
new Setter {
Property = Editor.BackgroundColorProperty,
Value = Color.FromHex("EEEEEE")
},
new Setter {
Property = Editor.TextColorProperty,
Value = Color.FromHex("333333")
},
new Setter {
Property = Editor.HorizontalOptionsProperty,
Value = LayoutOptions.FillAndExpand
},
new Setter {
Property = Editor.VerticalOptionsProperty,
Value = LayoutOptions.FillAndExpand
}
}
};
Resources.Add (editorStyle);
var pickerStyle = new Style (typeof(Picker)) {
Setters = {
new Setter {
Property = Picker.BackgroundColorProperty,
Value = Color.FromHex("EEEEEE")
},
new Setter {
Property = Picker.HorizontalOptionsProperty,
Value = LayoutOptions.FillAndExpand
},
new Setter {
Property = Picker.VerticalOptionsProperty,
Value = LayoutOptions.CenterAndExpand
}
}
};
Resources.Add (pickerStyle);
var datePickerStyle = new Style (typeof(DatePicker)) {
Setters = {
new Setter {
Property = DatePicker.BackgroundColorProperty,
Value = Color.FromHex("EEEEEE")
},
new Setter {
Property = DatePicker.HorizontalOptionsProperty,
Value = LayoutOptions.FillAndExpand
},
new Setter {
Property = DatePicker.VerticalOptionsProperty,
Value = LayoutOptions.CenterAndExpand
}
}
};
Resources.Add (datePickerStyle);
var buttonStyle = new Style (typeof(Button)) {
Setters = {
new Setter {
Property = Button.BackgroundColorProperty,
Value = Color.FromHex("DDDDDD")
},
//.........这里部分代码省略.........
示例12: InitGlobalStyles
private void InitGlobalStyles()
{
Resources = new ResourceDictionary();
var masterDetailstyle = new Style(typeof(MasterDetailPage))
{
Setters =
{
new Setter { Property = MasterDetailPage.BackgroundColorProperty, Value = Color.White },
new Setter { Property = MasterDetailPage.BackgroundColorProperty, Value = Color.White }
}
};
Resources.Add(masterDetailstyle);
//button
var buttonStyle = new Style(typeof(Button))
{
Setters =
{
new Setter {Property = Button.TextColorProperty, Value = Color.White},
new Setter {Property = Button.BackgroundColorProperty, Value = Color.FromRgb(254,39,61)}
}
};
Resources.Add(buttonStyle);
//nav page - can't superclass
var navPageStyle = new Style(typeof(NavigationPage))
{
Setters =
{
new Setter {Property = NavigationPage.BackButtonTitleProperty, Value = Color.Black},
new Setter {Property = NavigationPage.BarTextColorProperty, Value = Color.FromRgb(254,39,61)},
new Setter {Property = NavigationPage.TitleProperty, Value = Color.Black},
new Setter {Property = NavigationPage.TitleProperty, Value = TextAlignment.End},
new Setter {Property = NavigationPage.BackgroundColorProperty, Value = Color.White}
}
};
Resources.Add(navPageStyle);
//Base64EncodedContent page
var contentPageSTyle = new Style(typeof(ContentPage))
{
Setters =
{
new Setter {Property = ContentPage.BackgroundColorProperty, Value = Color.White},
new Setter {Property = ContentPage.TitleProperty, Value = Color.Black}
}
};
Resources.Add(contentPageSTyle);
var labelStyle = new Style(typeof(Label))
{
Setters =
{
new Setter {Property = Label.BackgroundColorProperty, Value = Color.White},
new Setter {Property = Label.TextColorProperty, Value = Color.Black},
new Setter {Property = Label.FontSizeProperty, Value = Font.SystemFontOfSize(NamedSize.Medium)}
}
};
Resources.Add(labelStyle);
var extendedLabelStyle = new Style(typeof(ExtendedLabel))
{
Setters =
{
new Setter {Property = ExtendedLabel.BackgroundColorProperty, Value = Color.White},
new Setter {Property = ExtendedLabel.TextColorProperty, Value = Color.Black},
new Setter {Property = ExtendedLabel.FontSizeProperty, Value = Font.SystemFontOfSize(NamedSize.Medium)},
new Setter {Property = ExtendedLabel.IsUnderlineProperty, Value = true},
}
};
Resources.Add(extendedLabelStyle);
var entryStyle = new Style(typeof(Entry))
{
Setters =
{
new Setter {Property = Entry.BackgroundColorProperty, Value = Color.White},
new Setter {Property = Entry.TextColorProperty, Value = Color.Black},
new Setter {Property = Entry.OpacityProperty, Value = 0.5}
}
};
Resources.Add(entryStyle);
var extendedEntry = new Style(typeof(ExtendedEntry))
{
Setters =
{
new Setter {Property = ExtendedEntry.BackgroundColorProperty, Value = Color.White},
new Setter {Property = ExtendedEntry.TextColorProperty, Value = Color.Black},
new Setter {Property = ExtendedEntry.PlaceholderTextColorProperty, Value = Color.Purple},
}
//.........这里部分代码省略.........
示例13: Update
public static void Update(ResourceDictionary resources)
{
resources.Add("LocalizedStrings", new LocalizedStrings());
resources.Add("ViewModelLocator", new ViewModelLocator(ServiceLocator.Resolve<IContainer>()));
resources.Add("DeviceSpecificsLocator", new DeviceSpecificsLocator(ServiceLocator.Resolve<IContainer>()));
}
示例14: SetupTheme
public static void SetupTheme(bool reload = true)
{
var _ColorString = StorageHelper.GetSetting(Contracts.Settings.PrimaryColor, Contracts.Settings.DefaultColor);
Uri _Path = null;
if (_ColorString.Equals(Windows.UI.Colors.Red.ToString()))
_Path = new Uri("ms-appx:/Styles/CustomStyles.Red.xaml");
else if (_ColorString.Equals(Windows.UI.Colors.Green.ToString()))
_Path = new Uri("ms-appx:/Styles/CustomStyles.Green.xaml");
else if (_ColorString.Equals(Windows.UI.Colors.Blue.ToString()))
_Path = new Uri("ms-appx:/Styles/CustomStyles.Blue.xaml");
else if (_ColorString.Equals(Windows.UI.Colors.Orange.ToString()))
_Path = new Uri("ms-appx:/Styles/CustomStyles.Orange.xaml");
var _Standard = new ResourceDictionary { Source = new Uri("ms-appx:/Styles/StandardStyles.xaml") };
var _Custom = new ResourceDictionary { Source = _Path };
var _Main = new ResourceDictionary { MergedDictionaries = { _Standard, _Custom } };
foreach (var item in App.Current.Resources)
{
if (!_Main.ContainsKey(item.Key))
_Main.Add(item);
}
App.Current.Resources = _Main;
// refresh the style immediately
if (reload)
Services.Navigation.Reload();
}
示例15: DynamicStylesPageCS
public DynamicStylesPageCS ()
{
Title = "Dynamic";
Icon = "csharp.png";
Padding = new Thickness (0, 20, 0, 0);
var baseStyle = new Style (typeof(View)) {
Setters = {
new Setter {
Property = View.VerticalOptionsProperty,
Value = LayoutOptions.CenterAndExpand
}
}
};
var blueSearchBarStyle = new Style (typeof(SearchBar)) {
BasedOn = baseStyle,
Setters = {
new Setter {
Property = SearchBar.FontAttributesProperty,
Value = FontAttributes.Italic
},
new Setter {
Property = SearchBar.PlaceholderColorProperty,
Value = Color.Blue
}
}
};
var greenSearchBarStyle = new Style (typeof(SearchBar)) {
Setters = {
new Setter {
Property = SearchBar.FontAttributesProperty,
Value = FontAttributes.None
},
new Setter {
Property = SearchBar.PlaceholderColorProperty,
Value = Color.Green
}
}
};
var buttonStyle = new Style (typeof(Button)) {
BasedOn = baseStyle,
Setters = {
new Setter {
Property = Button.FontSizeProperty,
Value = Device.GetNamedSize (NamedSize.Large, typeof(Button))
},
new Setter {
Property = Button.TextColorProperty,
Value = Color.Red
}
}
};
var searchBar1 = new SearchBar { Placeholder = "These SearchBar controls" };
searchBar1.SetDynamicResource (VisualElement.StyleProperty, "searchBarStyle");
var searchBar2 = new SearchBar { Placeholder = "are demonstrating" };
searchBar2.SetDynamicResource (VisualElement.StyleProperty, "searchBarStyle");
var searchBar3 = new SearchBar { Placeholder = "dynamic styles, " };
searchBar3.SetDynamicResource (VisualElement.StyleProperty, "searchBarStyle");
var searchBar4 = new SearchBar { Placeholder = "but this isn't dynamic", Style = blueSearchBarStyle };
var button = new Button { Text = "Change Style", Style = buttonStyle };
button.Clicked += OnButtonClicked;
Resources = new ResourceDictionary ();
Resources.Add ("blueSearchBarStyle", blueSearchBarStyle);
Resources.Add ("greenSearchBarStyle", greenSearchBarStyle);
Resources ["searchBarStyle"] = Resources ["blueSearchBarStyle"];
Content = new StackLayout {
Children = {
searchBar1,
searchBar2,
searchBar3,
searchBar4,
button
}
};
}