2012-07-15 73 views
0

我已經在應用程序資源應用資源不可用時,使用Unity引導程序

<Application.Resources> 
    <Style x:Key="gridTextBox"> 
     <Setter Property="TextBox.Margin" Value="0,5,5,5"/> 
    </Style> 
</Application.Resources> 

和資源定義了以下資源在主窗口

<TextBox Name="textBox1" Style="{StaticResource gridTextBox}"/> 

這個問題我被應用於像往常一樣在一個文本框我有,如果我通過Unity bootstrapper啓動應用程序,應用程序會在文本框資源上引發XamlParseException。但是如果我在app.xaml上使用startupUri,那麼應用程序按預期加載。我的引導程序看起來像這樣

public class Bootstrapper : UnityBootstrapper 
{ 
    protected override void InitializeShell() 
    { 
     base.InitializeShell(); 
     App.Current.MainWindow = (Window)Shell; 
     App.Current.MainWindow.Show(); 
    } 

    protected override DependencyObject CreateShell() 
    { 
     var shell = new MainWindow(); 
     return shell; 
    } 
} 

而且我的應用程序的啓動是如下

public partial class App : Application 
{ 
    protected override void OnStartup(StartupEventArgs e) 
    { 
     base.OnStartup(e); 
     new Bootstrapper().Run(); 
    } 
} 

我缺少什麼?

回答

1

改變你的App.xaml這一個:

<Application x:Class="UnityBootstrapperTest.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      > 
    <Application.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary> 
        <Style x:Key="gridTextBox"> 
         <Setter Property="TextBox.Margin" Value="0,5,5,5"/> 
        </Style> 
       </ResourceDictionary> 
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Application.Resources> 
</Application> 
+0

工程就像一個魅力,謝謝! :)你也許知道爲什麼我的版本不起作用,因爲AFAIK它應該是相同的? – Rok 2012-07-15 15:13:28

相關問題