当前位置: 首页>>代码示例>>C#>>正文


C# Windows.ResourceDictionary类代码示例

本文整理汇总了C#中System.Windows.ResourceDictionary的典型用法代码示例。如果您正苦于以下问题:C# ResourceDictionary类的具体用法?C# ResourceDictionary怎么用?C# ResourceDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResourceDictionary类属于System.Windows命名空间,在下文中一共展示了ResourceDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryFindDataTemplate

 protected abstract bool TryFindDataTemplate(
     ResourceDictionary resources, 
     FrameworkElement resourcesOwner,
     DependencyObject itemContainer,
     object item, 
     Type itemType,
     out DataTemplate dataTemplate);
开发者ID:squaredinfinity,项目名称:Foundation,代码行数:7,代码来源:ResourcesTraversingDataTemplateSelector.cs

示例2: VerifyResources

        /// <summary>
        /// 
        /// </summary>
        /// <param name="existing"></param>
        /// <param name="newResource"></param>
        /// <param name="validTypes"></param>
        /// <returns></returns>
        public static bool VerifyResources(this ResourceDictionary existing, ResourceDictionary newResource, params Type[] validTypes)
        {
            if (existing == null)
                throw new ArgumentNullException("existing");

            if (newResource == null)
                return false;

            if (validTypes != null && validTypes.Length > 0)
            {
                foreach (var resource in newResource.Values)
                {
                    if (!(resource.GetType().IsAssignableToAny(validTypes)))
                    {
                        MessageBox.Show(FindText("InvalidLanguageResourceType"), FindText("ApplicationTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
                        return false;
                    }
                }
            }

            var newKeys = newResource.Keys.Cast<object>();

            foreach (var existingKey in existing.Keys)
            {
                if (!newKeys.Contains(existingKey))
                {
                    var message = FindText("MissingLanguageResourceKey", existingKey);
                    MessageBox.Show(message, FindText("ApplicationTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }
            }

            return true;
        }
开发者ID:nankezhishi,项目名称:ClearMine,代码行数:41,代码来源:ResourceHelper.cs

示例3: LoadDictionary

        private static ResourceDictionary LoadDictionary()
        {
            if (cacheDictionary != null)
                return cacheDictionary;

            ResourceDictionary dictionary = null;
            try
            {
                dictionary =
                    (ResourceDictionary)Application.LoadComponent(
                        new Uri(@"Lang\" + CurrentCultureInfo.Name + ".xaml", UriKind.Relative));
            }
            catch
            {
            }

            //If dictionary is still null, use default language.
            if (dictionary == null)
                if (Application.Current.Resources.MergedDictionaries.Count > 0)
                    dictionary = Application.Current.Resources.MergedDictionaries[0];
                else
                    throw new Exception("No language file.");

            cacheDictionary = dictionary;

            return cacheDictionary;
        }
开发者ID:qwehkkk,项目名称:Locale-Emulator,代码行数:27,代码来源:I18n.cs

示例4: LogFormatter

 static LogFormatter()
 {
     _imageDict = new ResourceDictionary()
     {
         Source = new Uri("pack://application:,,,/Resources;component/Images/SystemImages.xaml")
     };
 }
开发者ID:shonwang,项目名称:sgs,代码行数:7,代码来源:LogFormatter.cs

示例5: SetLightDark

        public virtual void SetLightDark(bool isDark)
        {
            var existingResourceDictionary = Application.Current.Resources.MergedDictionaries
                .Where(rd => rd.Source != null)
                .SingleOrDefault(rd => Regex.Match(rd.Source.AbsolutePath, @"(\/MaterialDesignThemes.Wpf;component\/Themes\/MaterialDesignTheme\.)((Light)|(Dark))").Success);
            if (existingResourceDictionary == null)
                throw new ApplicationException("Unable to find Light/Dark base theme in Application resources.");

            var source = "pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme." + (isDark ? "Dark" : "Light") + ".xaml";

            //$"pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.{(isDark ? "Dark" : "Light")}.xaml";
            var newResourceDictionary = new ResourceDictionary() { Source = new Uri(source) };

            Application.Current.Resources.MergedDictionaries.Remove(existingResourceDictionary);
            Application.Current.Resources.MergedDictionaries.Add(newResourceDictionary);

            var existingMahAppsResourceDictionary = Application.Current.Resources.MergedDictionaries
                .Where(rd => rd.Source != null)
                .SingleOrDefault(rd => Regex.Match(rd.Source.AbsolutePath, @"(\/MahApps.Metro;component\/Styles\/Accents\/)((BaseLight)|(BaseDark))").Success);
            if (existingMahAppsResourceDictionary == null) return;

            source =
                         "pack://application:,,,/MahApps.Metro;component/Styles/Accents/" + (isDark ? "BaseDark" : "BaseLight") + ".xaml";
          //  $"pack://application:,,,/MahApps.Metro;component/Styles/Accents/{(isDark ? "BaseDark" : "BaseLight")}.xaml";
            var newMahAppsResourceDictionary = new ResourceDictionary { Source = new Uri(source) };

            Application.Current.Resources.MergedDictionaries.Remove(existingMahAppsResourceDictionary);
            Application.Current.Resources.MergedDictionaries.Add(newMahAppsResourceDictionary);
        }
开发者ID:markiemarkus,项目名称:TailBlazer4.5,代码行数:29,代码来源:PaletteHelper.cs

示例6: ChgReserveWindow

        public ChgReserveWindow()
        {
            InitializeComponent();

            if (Settings.Instance.NoStyle == 0)
            {
                ResourceDictionary rd = new ResourceDictionary();
                rd.MergedDictionaries.Add(
                    Application.LoadComponent(new Uri("/PresentationFramework.Aero, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/aero.normalcolor.xaml", UriKind.Relative)) as ResourceDictionary
                    //Application.LoadComponent(new Uri("/PresentationFramework.Classic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/Classic.xaml", UriKind.Relative)) as ResourceDictionary
                    );
                this.Resources = rd;
            }
            else
            {
                button_chg_reserve.Style = null;
                button_del_reserve.Style = null;
                button_cancel.Style = null;
            }

            comboBox_service.ItemsSource = ChSet5.Instance.ChList.Values;
            comboBox_sh.ItemsSource = CommonManager.Instance.HourDictionary.Values;
            comboBox_eh.ItemsSource = CommonManager.Instance.HourDictionary.Values;
            comboBox_sm.ItemsSource = CommonManager.Instance.MinDictionary.Values;
            comboBox_em.ItemsSource = CommonManager.Instance.MinDictionary.Values;
            comboBox_ss.ItemsSource = CommonManager.Instance.MinDictionary.Values;
            comboBox_es.ItemsSource = CommonManager.Instance.MinDictionary.Values;
        }
开发者ID:Telurin,项目名称:EDCB,代码行数:28,代码来源:ChgReserveWindow.xaml.cs

示例7: PackagesProviderBase

        protected PackagesProviderBase(
            IPackageRepository localRepository, 
            ResourceDictionary resources, 
            ProviderServices providerServices, 
            IProgressProvider progressProvider, 
            ISolutionManager solutionManager)
        {
            if (resources == null)
            {
                throw new ArgumentNullException("resources");
            }

            if (providerServices == null)
            {
                throw new ArgumentNullException("providerServices");
            }

            if (solutionManager == null)
            {
                throw new ArgumentNullException("solutionManager");
            }

            _localRepository = localRepository;
            _providerServices = providerServices;
            _progressProvider = progressProvider;
            _solutionManager = solutionManager;
            _resources = resources;
            _outputConsole = new Lazy<IConsole>(() => providerServices.OutputConsoleProvider.CreateOutputConsole(requirePowerShellHost: false));
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:29,代码来源:PackagesProviderBase.cs

示例8: SharedThemeService

 public SharedThemeService(ResourceDictionary resourceDictionary)
 {
     _resourceDictionary = resourceDictionary;
     _themes = new BehaviorSubject<IEnumerable<ITheme>>(Enumerable.Empty<ITheme>());
     _activeTheme = new BehaviorSubject<ITheme>(null);
     _themesMap = new Dictionary<string, ITheme>();
 }
开发者ID:a-wall,项目名称:radar,代码行数:7,代码来源:SharedThemeService.cs

示例9: 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;
        }
开发者ID:kib357,项目名称:Ester2,代码行数:32,代码来源:ResourceDictionaries.cs

示例10: LoadStyle

 public void LoadStyle()
 {
     Uri resourceLocater = HbRelogManager.Settings.UseDarkStyle ? new Uri("/styles/ExpressionDark.xaml", UriKind.Relative) : new Uri("/styles/BureauBlue.xaml", UriKind.Relative);
     var rDict = new ResourceDictionary { Source = resourceLocater };
     Resources.MergedDictionaries.Clear();
     Resources.MergedDictionaries.Add(rDict);
 }
开发者ID:vanasis,项目名称:HBRelog,代码行数:7,代码来源:MainWindow.xaml.cs

示例11: ThemeManager

 public ThemeManager()
 {
     this.themeResources = new ResourceDictionary
                               {
                                   Source = new Uri("pack://application:,,,/Caliburn.Metro.Demo;component/Resources/Theme1.xaml")
                               };
 }
开发者ID:gencer,项目名称:MahApps.Metro,代码行数:7,代码来源:ThemeManager.cs

示例12: ChangeTheme

        internal static void ChangeTheme(string theme)
        {
            var app = System.Windows.Application.Current;
            if (string.IsNullOrEmpty(theme))
            {
                if (currentUri != null)
                {
                    var oldtheme = app.Resources.MergedDictionaries[app.Resources.MergedDictionaries.Count - 1];
                    //FindName(currentUri.OriginalString) as ResourceDictionary;
                    app.Resources.MergedDictionaries.Remove(oldtheme);
                }
                CurrentSkin = null;
                currentUri = null;
                return;
            }

            Uri resourceLocator = new Uri("BackBock;Component/Themes/" + theme + "/Theme.xaml", UriKind.Relative);
            //Application.Current.Resources =  Application.LoadComponent(resourceLocator) as ResourceDictionary;
            //var dictionary = System.Windows.Application.LoadComponent(resourceLocator) as ResourceDictionary;
            var dictionary = new ResourceDictionary();
            dictionary.Source = resourceLocator;
            if (currentUri != null)
            {
                var oldtheme = app.Resources.MergedDictionaries[app.Resources.MergedDictionaries.Count - 1];
                //FindName(currentUri.OriginalString) as ResourceDictionary;
                app.Resources.MergedDictionaries.Remove(oldtheme);
            }

            app.Resources.MergedDictionaries.Add(dictionary);
            //app.Resources = dictionary;
            CurrentSkin = theme;
            currentUri = resourceLocator;
        }
开发者ID:Jedzia,项目名称:BackBock,代码行数:33,代码来源:SkinsManager.cs

示例13: RegisterResources

        private static void RegisterResources(string moduleName = null)
        {
            var dictionary = new ResourceDictionary();
            
            

            if (string.IsNullOrEmpty(moduleName))
            {
                StackTrace stackTrace = new StackTrace();
                Assembly assembly = stackTrace.GetFrame(2).GetMethod().Module.Assembly;
                string assemblyName = assembly.FullName;
                string[] nameParts = assemblyName.Split(',');
                moduleName = nameParts[0];
            }
#if SILVERLIGHT

            StreamResourceInfo resourceInfo = Application.GetResourceStream(new Uri(moduleName + ";component/Resources/ModuleResources.xaml", UriKind.Relative));
            if (resourceInfo == null) return;
            var resourceReader = new StreamReader(resourceInfo.Stream);
            string xaml = resourceReader.ReadToEnd();
            var resourceTheme = XamlReader.Load(xaml) as ResourceDictionary;
            Application.Current.Resources.MergedDictionaries.Add(resourceTheme);
#else
        dictionary.Source = new Uri(
            "pack://application:,,,/" + moduleName + ";component/Resources/ModuleResources.xaml");
        Application.Current.Resources.MergedDictionaries.Add(dictionary);
#endif
        }
开发者ID:arielbh,项目名称:SuiteValue.UI,代码行数:28,代码来源:ModuleBase.cs

示例14: ApplyConvention

        public void ApplyConvention(Assembly assembly, DictionaryEntry entry)
        {
            string assemblyName = assembly.GetName().Name;
            string key = entry.Key as string;
            key = key.Replace(".baml", ".xaml");

            string uriString = String.Format("pack://application:,,,/{0};Component/{1}", assemblyName, key);

            try
            {
                if (!uriString.ToUpper().Contains("VIEW.XAML")
                    && !uriString.ToUpper().Contains("APP.XAML"))
                {
                    var dictionary = new ResourceDictionary
                                         {
                                             Source = new Uri(uriString)
                                         };

                    Application.Current.Resources.MergedDictionaries.Add(dictionary);
                }
            }
            catch
            {
                // do nothing. This allows for user controls to 'not' be loaded into the
                // Resource Dictionary
            }
        }
开发者ID:RookieOne,项目名称:JBsWpfExamples,代码行数:27,代码来源:ResourceDictionaryConvention.cs

示例15: FindBestMatchInResourceDictionary

        // Given a ResourceDictionary and a set of keys, try to find the best
        //  match in the resource dictionary.
        private static object FindBestMatchInResourceDictionary(
            ResourceDictionary table, ArrayList keys, int exactMatch, ref int bestMatch)
        {
            object resource = null;
            int k;

            // Search target element's ResourceDictionary for the resource
            if (table != null)
            {
                for (k = 0; k < bestMatch; ++k)
                {
                    object candidate = table[keys[k]];
                    if (candidate != null)
                    {
                        resource = candidate;
                        bestMatch = k;

                        // if we found an exact match, no need to continue
                        if (bestMatch < exactMatch)
                            return resource;
                    }
                }
            }

            return resource;
        }
开发者ID:kasicass,项目名称:kasicass,代码行数:28,代码来源:ItemContainerTemplateSelector.cs


注:本文中的System.Windows.ResourceDictionary类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。