我一直在WPF項目上工作了一段時間,但在2個月內還沒有觸及它。 現在我回來了,我有以下問題:從DynamicResource到StaticResource的WPF
我使用合併字典來創建皮膚,並在運行時輕鬆交換它們。 但是,每個皮膚在運行時不會更改。但是,當我對此不以爲然時,我只是遵循了一堆教程,而且我到處都使用了DynamicResource,甚至不知道是否應該使用StaticResource。
結果是,當我嘗試將我的應用程序發送給使用Windows XP(我使用七)的朋友。盧娜的主題是拋在我的應用程序,使設計醜陋... 據我瞭解它來自DynamicResource。
所以現在我想改成StaticResource,我只是試圖用「StaticResource」替換每個「DynamicResource」。它拋出我這個異常:
Message = "'La valeur fournie sur 'System.Windows.StaticResourceExtension' a levé une exception.' numéro de ligne '8' et position de ligne '230'."
In english, it means: Message = "'The value given to 'System.Windows.StaticResourceExtension' threw an exception.' line number '8' and position on the line '230'.
然後我把try/catch塊有問題的一個更好的主意:
{"Impossible de trouver la ressource nommée'styleBackground'. Les noms de ressources respectent la casse."}
英文:Impossible to find the resource named 'styleBackground'. The resource names are case sensitive.
這是關於一個TabItem的。
所以這裏有兩個問題: 我是否通過將DynamicResource更改爲StaticResource來做正確的事情? 如果是這樣,我需要做什麼?
謝謝,
FB。
編輯:程序得到的最後這些線路的錯誤:
<Window x:Class="Sc2ReplayMonkey.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:local="clr-namespace:Sc2ReplayMonkey" ResizeMode="CanResize"
Title="Starcraft II Replay Monkey"
Width="991" Icon="Resources\Icons\SC2_Replay_Monkey.png"
WindowStartupLocation="CenterScreen" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="1024" Height="774" Visibility="Visible" Foreground="#00000000" Margin="0">
WPF不擅長輸出錯誤。如果使用Visual Studio,請嘗試顯示輸出窗口。它應該給你更多關於這個問題的信息。 – 2011-03-31 21:29:55
我很害怕它沒有多大幫助,它輸出: ''Sc2ReplayMonkey.vshost.exe'(託管(v4.0.30319)):加載'C:\ Windows \ Microsoft.Net \ assembly \ GAC_32 \ mscorlib'Sc2ReplayMonkey .vshost.exe'(Managed(v4.0.30319)):Loaded'C:\ Windows \ Microsoft.Net \ assembly \ GAC_MSIL \ System.Xaml.resources \ v4.0_4.0.0.0_fr_b77a5c561934e089 \ System.Xaml.resources.dll ' 'Sc2ReplayMonkey.vshost.exe'(Managed(v4.0.30319)):Loaded'C:\ Windows \ Microsoft.Net \ assembly \ GAC_MSIL \ mscorlib.resources \ v4.0_4.0.0.0_fr_b77a5c561934e089 \ mscorlib.resources.dll ' ' – 2011-03-31 21:33:47
我發現我的錯誤,當切換到StaticResource時,應用程序需要在啓動時加載每個資源,並且我只加載基本字典,沒有皮膚。 – 2011-03-31 21:57:23