1

如何使用 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>
4

1 回答 1

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 { }
    }
}
于 2013-08-22T12:58:35.353 回答