本文整理汇总了C#中System.Windows.ResourceDictionary.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceDictionary.Add方法的具体用法?C# ResourceDictionary.Add怎么用?C# ResourceDictionary.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.ResourceDictionary
的用法示例。
在下文中一共展示了ResourceDictionary.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AdvancedEditWindow
public AdvancedEditWindow(a_animes AnimeToChange, AniMoDBEntities db)
{
ResourceDictionary d = new ResourceDictionary();
d.Add("vm", new AdvancedEditVM(db, AnimeToChange));
this.Resources.MergedDictionaries.Add(d);
InitializeComponent();
}
示例2: Main
public static void Main(string[] args)
{
var application = new Application();
var resourceDictionary = new ResourceDictionary();
resourceDictionary.Add("Dunno", new LinearGradientBrush());
resourceDictionary.Add("Dunno1", new LinearGradientBrush(Color.FromRgb(0x35, 0x56, 0xc6), Color.FromRgb(0x20, 0x39, 0x77),
new Point(0, 0), new Point(0, 1)));
resourceDictionary.Add("Dunno2", new LinearGradientBrush(Colors.Peru, Colors.Coral, new Point(0, 0), new Point(0, 1)));
application.Resources = resourceDictionary;
var cb = new ContainerBuilder();
cb.RegisterModule<TurbinaModule>().RegisterModule<TurbinaNodesModule>();
var container = cb.Build();
application.Run(new MainWindow(container));
}
示例3: ExportViewToXaml
public static void ExportViewToXaml( ViewBase view, string fileName )
{
if( view == null )
throw new ArgumentNullException( "view" );
object value;
DependencyProperty dp;
ResourceDictionary resourceDictionary = new ResourceDictionary();
Type viewType = view.GetType();
Style viewStyle = new Style( viewType );
foreach( FieldInfo fieldInfo in viewType.GetFields( BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static ) )
{
dp = fieldInfo.GetValue( view ) as DependencyProperty;
if( dp != null )
{
value = view.ReadLocalValue( dp );
if( value != DependencyProperty.UnsetValue )
viewStyle.Setters.Add( new Setter( dp, value ) );
}
}
resourceDictionary.Add( viewType, viewStyle );
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
using( XmlWriter xmlWriter = XmlWriter.Create( fileName, settings ) )
{
XamlWriter.Save( resourceDictionary, xmlWriter );
}
}
示例4: GetDictionary
//private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
public static ResourceDictionary GetDictionary(string relativePath = @"Resources\Dictionaries")
{
var mergedDictionary = new ResourceDictionary();
string path = Path.Combine(HttpRuntime.AppDomainAppPath, relativePath);
if (Directory.Exists(path))
foreach (string fileName in Directory.GetFiles(path).Where(f => f.EndsWith(".xaml")))
using (var fs = new FileStream(fileName, FileMode.Open))
{
try
{
var xr = new XamlReader();
var tmp = (ResourceDictionary)XamlReader.Load(fs);
foreach (string key in tmp.Keys)
if (tmp[key] is Canvas)
{
mergedDictionary.Add(key, tmp[key]);
}
}
catch (Exception)
{
//_logger.Error(ex.Message);
}
}
else
Directory.CreateDirectory(path);
return mergedDictionary;
}
示例5: FillupResource
public void FillupResource(ResourceDictionary res)
{
foreach (var fd in FrameDescriptions.Values)
{
res.Add(GetBrushResourceNameForDescriptor(fd.Descriptor),
new SolidColorBrush(fd.HighlightColor));
}
}
示例6: ChangeRd
private void ChangeRd(ResourceDictionary rd, string newKey, object newValue)
{
if (!rd.Contains(newKey))
{
rd.Add(newKey, newValue);
SaveChange();
}
}
示例7: CreateAccentColorResourceDictionary
public static ResourceDictionary CreateAccentColorResourceDictionary(this Color color)
{
if (_accentColorResourceDictionary != null)
{
return _accentColorResourceDictionary;
}
var resourceDictionary = new ResourceDictionary();
resourceDictionary.Add("NotificationAccentColor", color);
resourceDictionary.Add("NotificationAccentColorBrush", new SolidColorBrush((Color) resourceDictionary["NotificationAccentColor"]));
var application = Application.Current;
var applicationResources = application.Resources;
applicationResources.MergedDictionaries.Insert(0, resourceDictionary);
_accentColorResourceDictionary = resourceDictionary;
return applicationResources;
}
示例8: WrapInResourceDictionary
public static ResourceDictionary WrapInResourceDictionary(object obj)
{
var rd = new ResourceDictionary();
var list = obj as IEnumerable;
if (list != null)
{
int i = 1;
foreach (var o in list)
{
rd.Add("Model" + i, o);
i++;
}
}
else
{
rd.Add("Model", obj);
}
return rd;
}
示例9: ApplyResourceDictionary
private static void ApplyResourceDictionary(ResourceDictionary newRd, ResourceDictionary oldRd)
{
foreach (DictionaryEntry r in newRd)
{
if (oldRd.Contains(r.Key))
oldRd.Remove(r.Key);
oldRd.Add(r.Key, r.Value);
}
}
示例10: Tests
public Tests()
{
if (applicationService == null)
{
Console.WriteLine("Initialisation des Tests");
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
{
Source =
new Uri(
"/Proteca.SilverlightUnitTest;component/Assets/Styles.xaml",
UriKind.RelativeOrAbsolute)
});
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
{
Source =
new Uri(
"/Proteca.SilverlightUnitTest;component/Assets/GridView.xaml",
UriKind.RelativeOrAbsolute)
});
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
{
Source =
new Uri(
"/Proteca.SilverlightUnitTest;component/Assets/Boutons.xaml",
UriKind.RelativeOrAbsolute)
});
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
{
Source =
new Uri(
"/Proteca.SilverlightUnitTest;component/Assets/TileView.xaml",
UriKind.RelativeOrAbsolute)
});
ResourceDictionary dic = new ResourceDictionary();
dic.Add("ApplicationResources", new Proteca.Silverlight.ApplicationResources());
Application.Current.Resources.MergedDictionaries.Add(dic);
if (Application.Current.Resources.Any(r => r.Key.ToString() == "ServiceHostAdress"))
{
Application.Current.Resources.Remove("ServiceHostAdress");
}
Application.Current.Resources.Add("ServiceHostAdress", "http://verd174:90/");
if (!Application.Current.Resources.Any(r => r.Key.ToString() == "DebugLogin"))
{
Application.Current.Resources.Add("DebugLogin", "n.cossard");
}
if (applicationService == null)
{
applicationService = new ApplicationService();
applicationService.StartService(null);
}
}
}
示例11: GetItemContainerStyle
private static Style GetItemContainerStyle()
{
Style listBoxItemStyle = new Style(typeof(ListBoxItem));
listBoxItemStyle.Setters.Add(new Setter(ListBox.FocusVisualStyleProperty, null)); // убираем рамку из точек вокруг выделенного элемента
listBoxItemStyle.Setters.Add(new Setter(ListBox.PaddingProperty, new Thickness(0))); // убираем отступы от края родительского элемента
listBoxItemStyle.Setters.Add(new Setter(ListBoxItem.MarginProperty, new Thickness(0, 0, 0, 1))); // добавляем отступ снизу каждого элемента
ResourceDictionary resources = new ResourceDictionary();
resources.Add(SystemColors.HighlightBrushKey, new SolidColorBrush(Colors.Transparent));
listBoxItemStyle.Resources = resources;
return listBoxItemStyle;
}
示例12: Register
public static void Register(ResourceDictionary resources)
{
var buttonTemplate = new FrameworkElementFactory(typeof(ButtonTemplate));
var controlTemplate = new ControlTemplate(typeof(ToggleButton));
controlTemplate.VisualTree = buttonTemplate;
var style = new Style(typeof(ToggleButton));
style.Setters.Add(new Setter(Control.TemplateProperty, controlTemplate));
resources.Add(typeof(ToggleButton), style);
}
示例13: CreateRemoteAgent
/// <summary>
/// Create a remote agent with the given name
/// </summary>
public static RemoteAgentTag CreateRemoteAgent(string agentName, ITextView view, IEditorFormatMap formatMap)
{
Dictionary<string, RemoteAgentTag> existingAgents = GetExistingAgents(view);
RemoteAgentTag agent;
if (existingAgents.TryGetValue(agentName, out agent))
return agent;
var brushes = _brushes[existingAgents.Count % _brushes.Count];
ResourceDictionary agentDictionary = new ResourceDictionary();
agentDictionary.Add(MarkerFormatDefinition.BorderId, brushes.Item1);
agentDictionary.Add(MarkerFormatDefinition.FillId, brushes.Item2);
formatMap.AddProperties(agentName, agentDictionary);
agent = new RemoteAgentTag(agentName);
existingAgents[agentName] = agent;
return agent;
}
示例14: Register
public static void Register(ResourceDictionary resources)
{
var textBoxTemplate = new FrameworkElementFactory(typeof(TextBoxTemplate));
textBoxTemplate.AppendChild(new FrameworkElementFactory(typeof(ScrollViewer), "PART_ContentHost"));
var controlTemplate = new ControlTemplate(typeof(TextBox));
controlTemplate.VisualTree = textBoxTemplate;
var style = new Style(typeof(TextBox));
style.Setters.Add(new Setter(Control.TemplateProperty, controlTemplate));
resources.Add(typeof(TextBox), style);
}
示例15: TemplateAndStyleFindDefaultTest
public void TemplateAndStyleFindDefaultTest()
{
Style style = new Style { TargetType = typeof(Control) };
style.Setters.Add(new Setter { Property = new DependencyPropertyPathElement(FrameworkElement.WidthProperty), Value = 100 });
string text = @"
<ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' TargetType='{x:Type Control}'>
<FrameworkElement/>
</ControlTemplate>";
ControlTemplate controlTemplate = XamlLoader.Load(XamlParser.Parse(text)) as ControlTemplate;
ResourceDictionary resources = new ResourceDictionary();
resources.Add(new StyleKey(typeof(Control)), style);
resources.Add(new TemplateKey(typeof(Control)), controlTemplate);
Control control = new Control();
control.Resources = resources;
Assert.AreEqual(style, control.Style);
Assert.AreEqual(controlTemplate, control.Template);
}