【问题标题】:How to load style using xamlreader如何使用 xamlreader 加载样式
【发布时间】:2013-08-22 20:58:35
【问题描述】:

如何使用 XamlReader.Load() 从 xaml 下面加载样式

<Window
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
>
<ResourceDictionary>
        <Style x:Key="LastRowHighlighted"
        BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=RowStyle}}"
               TargetType="{x:Type dxg:GridRowContent}">
        </Style>
</ResourceDictionary>

【问题讨论】:

    标签: wpf styles xamlreader


    【解决方案1】:

    试试这样的:

    public void LoadStyle(string fileName)
    {
        if (File.Exists(fileName))
        {
            try
            {
                using (FileStream fileStream = new FileStream(fileName, FileMode.Open, 
    FileAccess.Read, FileShare.Read))
                {
                    ResourceDictionary resourceDictionary = (ResourceDictionary)XamlReader.
    Load(fileStream);
                    Resources.MergedDictionaries.Clear(); // optional
                    Resources.MergedDictionaries.Add(resourceDictionary);
                }
            }
            catch { }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 2019-08-18
      • 2018-04-21
      • 2017-07-31
      • 2011-01-14
      • 2014-02-06
      相关资源
      最近更新 更多