2012-03-16 65 views
0

在我的應用我創建一個樣式像這樣:如何保存窗口資源

Dim ButtonStyle as new Style(GetType(Button)) 
ButtonStyle.Setters.Add(New Setter(BackgroundProperty,Brushes.Gray)) 
Resources.Add("ButtonStyle", ButtonsStyle) 

而且我想保存這種風格應用程序退出時,這樣當應用程序運行下一次將加載我的新風格。可能嗎?

回答

0

在C#中遺憾:

public partial class App : Application 
{ 
    public App() 
    { 
     if (string.IsNullOrWhiteSpace(Settings.Default.Resources)) 
     { 
      Style buttonStyle = new Style(typeof(Button)); 
      buttonStyle.Setters.Add(new Setter(Button.BackgroundProperty, Brushes.Red)); 
      Resources.Add(typeof(Button), buttonStyle); 
     } 
     else 
      Resources = XamlReader.Parse(Settings.Default.Resources) as ResourceDictionary; 
    } 

    protected override void OnExit(ExitEventArgs e) 
    { 
     base.OnExit(e); 

     // Save styles 
     Settings.Default.Resources = XamlWriter.Save(Resources); 
     Settings.Default.Save(); 
    } 
} 
+0

@Cobold沒有幫助? – Jonas 2012-03-20 09:39:39