因爲幾天後,打開我的任何一個xaml文件時,出現「Resource not found」消息,但編譯並執行該應用程序卻沒有問題。我正在使用MahApps.Metro進行UI設計,並已嘗試清理並重建整個解決方案,並使用Visual Studio Blend 2015「重新安裝」MahApps.Metro(版本1.4.3)軟件包。在設計時未找到C#資源
我的App.xaml看起來是這樣的:(有定義更多的風格,但WindowStyle顯示了「資源無法解析」錯誤)
<Application x:Class="Edge_Player.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Edge_Player"
xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:system="clr-namespace:System;assembly=mscorlib"
StartupUri="Player.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Theme/Dark.xaml"/>
<ResourceDictionary Source="Localization/StringResources.xaml"/>
<ResourceDictionary Source="Resources/Icons/Icons.xaml"/>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatButton.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatSlider.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="Theme/Base/Dark.xaml"/>
<ResourceDictionary Source="Theme/Accents/Orange.xaml"/>
<ResourceDictionary Source="Controls/Slider.xaml"/>
<ResourceDictionary Source="Controls/Menu.xaml"/>
</ResourceDictionary.MergedDictionaries>
<system:Double x:Key="WindowTitleFontSize">14</system:Double>
<BitmapImage x:Key="DesignCover" UriSource="Resources/emptyCover.png"/>
<BitmapImage x:Key="DesignImage" UriSource="Resources/osu_mp_wallpaper.jpg"/>
<Style x:Key="WindowStyle"
TargetType="{x:Type metro:MetroWindow}"
BasedOn="{StaticResource {x:Type metro:MetroWindow}}">
<Setter Property="Background" Value="{DynamicResource Primary}"/>
<Setter Property="Foreground" Value="{DynamicResource Accent}"/>
<Setter Property="BorderBrush" Value="{DynamicResource Border}"/>
<Setter Property="GlowBrush" Value="{DynamicResource Border}"/>
<Setter Property="NonActiveBorderBrush" Value="{DynamicResource Warn}"/>
<Setter Property="NonActiveGlowBrush" Value="{DynamicResource Warn}"/>
<Setter Property="NonActiveWindowTitleBrush" Value="{DynamicResource PrimaryDark}"/>
<Setter Property="WindowTitleBrush" Value="{DynamicResource PrimaryDark}"/>
<Setter Property="ShowIconOnTitleBar" Value="False"/>
</Style>
所有的「WindowStyle」使用的DynamicResources都在一個單獨的文件中定義。
所以,當你complie,一切工作正常和資源工作? 如果是這樣,請嘗試重建項目並清理它,它通常會解決此類情況。 –
我已經嘗試清潔和重建,不起作用 – Blacktasty
@Blacktasty有時候Visual Studio需要關閉並重新打開(個人體驗),你有沒有試過? –