2013-08-22 53 views
0

加載風格我如何可以加載風格從下面使用XamlReader.Load()XAML如何使用xamlreader

<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> 

回答

0

嘗試是這樣的:

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 { } 
    } 
} 
相關問題