Skip to content

Instantly share code, notes, and snippets.

@JKamsker
Last active July 3, 2017 14:15
Show Gist options
  • Save JKamsker/2442e8e9177525c862aee771d402abbb to your computer and use it in GitHub Desktop.
Save JKamsker/2442e8e9177525c862aee771d402abbb to your computer and use it in GitHub Desktop.
Add merged directories from the codebehind
//Sample Usage for mahapps:
//WpfDictionaries.AddDirectories("MahApps.Metro", "component/Styles", new string[] { "Controls", "Fonts", "Colors", "Accents/Blue", "Accents/BaseLight" }, "xaml");
internal class WpfDictionaries
{
public static void AddDirectories(string domain, string prefix, IEnumerable<string> fileNames, string suffix)
{
fileNames.ForEach(x =>
{
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri($"pack://application:,,,/{domain};{prefix}/{x}.{suffix}", UriKind.RelativeOrAbsolute)
});
});
}
}
internal static class Extensions{
public static void ForEach<T>(this IEnumerable<T> input, Action<T> toRunAct)
{
foreach (var put in input)
{
toRunAct(put);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment