簡體   English   中英

WPF - 資源未從Generic.xaml加載

[英]WPF - Resource not loading from Generic.xaml

主題\\ Generic.xaml:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="WPF Commons;component/Controls/Layout/Foo/FooItem.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

控制\\布局\\富\\ FooItem.xaml:

<Style TargetType="{x:Type l:FooItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type l:FooItem}">
                <Border>
                    <ContentPresenter ContentSource="Header" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


如果我將整個樣式復制到我的usercontrol資源中,它可以正常工作。 但是,如果我不這樣做,則usercontrol顯示為空。 在Expression Blend 4中,我右鍵單擊並選擇了Edit Template >,但它不會讓我選擇Edit a Copy...這讓我相信某些內容嚴重錯誤並且Generic.xaml沒有正確加載。 我認為它是Generic.xaml,因為如果我刪除MergedDictionary調用並將xaml樣式直接復制/粘貼到Generic.xaml中,它仍然無效。

我會猜測你改變了你的AssemblyInfo.cs文件並更改(或刪除)了以下行:

[assembly: ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
    //(used if a resource is not found in the page, 
    // or application resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
    //(used if a resource is not found in the page, 
    // app, or any theme specific resource dictionaries)
)]

你需要告訴大會你的ThemeInfo。 :)

從我的博客復制:http: //zoomicon.wordpress.com/2012/06/10/what-to-do-if-generic-xaml-doesnt-get-loaded-for-wpf-control/

在您需要的Properties \\ AssemblyInfo.cs的開頭(注意Silverlight中沒有使用/需要):使用System.Windows;

...

請注意,如果項目未在解決方案資源管理器中顯示“屬性”節點,則必須使用正確的模板創建新項目(對於WPF自定義控件),或者右鍵單擊項目,選擇“屬性”,然后按“組件”。信息按鈕並輸入一些虛擬值,然后單擊確定以創建屬性節點(也創建屬性子文件夾和AssemblyInfo.cs文件)。

您可以展開(下拉)解決方案資源管理器中的特殊“屬性”節點,然后打開AssemblyInfo.cs並添加上述內容(如果缺少)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM