2013-10-08 27 views
2

很奇怪的情況。我有以下的App.xaml基於在Designer中未顯示的窗口上設置的樣式的樣式(僅在運行時)

<Application x:Class="BrokenBG.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      StartupUri="MainWindow.xaml"> 
    <Application.Resources> 

     <Style x:Key="WindowStyleBase" TargetType="ContentControl" > 
      <Setter Property="Background" Value="Red" /> 
      </Style> 
     <Style x:Key="WindowStyle" TargetType="{x:Type Window}" BasedOn="{StaticResource WindowStyleBase}" /> 

    </Application.Resources> 
</Application> 

並與樣式設置一個簡單的空窗:

<Window x:Class="BrokenBG.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525" Style="{StaticResource WindowStyle}"> 
    <Grid> 

    </Grid> 
</Window> 

當我運行的應用程序一切都很好。我看到紅色的bg。 但我在設計師看不到它。上面的代碼是我在另一個大型項目中遇到的重複案例。

當我將窗口樣式從WindowStyle更改爲WindowStyleBase時,我可以直接在設計器中看到紅色背景顏色。

這可以修復嗎?我的窗戶有一個黑暗的主題,因此我無法在Visual Studio/Blend中設計視圖,因爲在運行時背景是白色和黑色(我的文字是白色的)

看起來設計師在使用BasedOn解析時遇到了問題? (不確定)

回答

2

有效的一件事,即使它不會編譯。 您可以更改基於動態資源的靜態資源。

它會突然開始在設計器中工作,但這不會編譯。

我甚至將紅色變爲藍色,並更新了設計師。

+0

感謝您的提示,我會嘗試,因爲沒有其他選擇。但修復與另一個錯誤似乎很奇怪:/ – Samuel

+0

嗯,我可以證實這個解決方法,因爲它似乎工作。如果沒有解釋會出現,我會將其標記爲答案。謝謝 – Samuel

相關問題