SORU
4 AĞUSTOS 2009, Salı


Sorun Birleştirilmiş bir Sözlük içeren Kaynak bir Sözlük referans

Bir kütüphane, CommonLibraryWpfThemes, Kaynak Sözlük XAML birkaç dosya var. Themes/generic.xml dosyamı bir ResourceDictionary içerir.Birlikte, diğer tüm dosyaları birleştirir MergedDictionaries beyannamesi.

Jenerik.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/BrushDictionary.xaml" />
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/TextBlockDictionary.xaml" />
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/LabelDictionary.xaml" />
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/ButtonDictionary.xaml" />
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Uygulama projemde, CommonLibraryWpfThemes bir başvuru var, ve ben açıkça referans benim App Generic.xml .xaml dosyası.

App.xaml -- BAŞARISIZ olur

<Application
    x:Class="MyApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary
            Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" />
    </Application.Resources>
</Application>

Bu işe yaramıyor. Uygulamamı çalıştırdığımda aşağıdaki hatayı alıyorum:

System.Windows.Markup.XamlParseException occurred
  Message="Cannot find resource named '{_fadedOrangeBrush}'. Resource names are case sensitive.  Error at object 'System.Windows.Setter' in markup file 'CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml' Line 18 Position 13."
  Source="PresentationFramework"
  LineNumber=18
  LinePosition=13

Genel içeriğini yerleştirin.xaml Uygulaması içine.xaml doğrudan, her şey düzgün çalışır:

App.xaml -- BAŞARILI olur

<Application
    x:Class="MyApp.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
                    Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/BrushDictionary.xaml" />
                <ResourceDictionary
                    Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/TextBlockDictionary.xaml" />
                <ResourceDictionary
                    Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/LabelDictionary.xaml" />
                <ResourceDictionary
                    Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/ButtonDictionary.xaml" />
                <ResourceDictionary
                    Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>


Belki de yanlış bir şekilde bu konuda gidiyorum. Amacım kolay tüm dosyaları tek tek liste girmek zorunda kalmadan birden fazla uygulamaya ait tüm tema kaynaklarımı başvuru yapmaktır. Tavsiye bunu yapmak için bir yol var mı? (Not: birden fazla tema sadece tema arasında geçiş yapmak için çalışmıyorum.)

Bir bonus olarak, eğer birisi Visual Studio tasarımcısı bozmadan harici bir kütüphane kaynakları başvuru nasıl olduğunu bana söyleyebilir eğer iyi olurdu.

Teşekkürler.

DÜZENLEME:

ResourceDictionary sarma bir ResourceDictionary denedim.MergedDictionary eleman, ama o da işe yaramadı aynı hatayı alıyorum):

<Application
    x:Class="MyApp.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
                    Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

CEVAP
12 Kasım 2010, Cuma


Burada benzer bir soru daha önce yanıtlanmış, Adding a Merged Dictionary to a Merged Dictionary soruya bakın.

Bu optimizasyon bir hata, Microsoft Connect / DefaultStyleKey style not found in inner MergedDictionaries bkz

Her oluşturulması nesne Varsayılan bir stil varsa, XAML, (stil w/ Türü olan bir anahtar yani) stil uygulanmalıdır. Gibi çeşitli performans hayal var bunu yapmak için en iyi duruma getirme () ima mümkün olduğunca hafif arama. Bir içinde görünmemesi bunlardan Kaynak olmadıkça Sözlükler “varsayılan içeren olarak işaretlenir ”. Stilleri Tüm eğer bir hata var: varsayılan stilleri birleştirilmiş iç içe üç düzeyde derin (ya da sözlük daha derin) üst sözlük değil arama atlıyor yani işaretli olsun. Geçici çözüm, bir varsayılan koymaktır Bir şey tarzı bir şey, Sözlük kök.

Yani kök sözlük boş bir stil ekleme düzeltmeleri bu. Örnek

<Application x:Class="MyApp.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 
                    Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" /> 
                </ResourceDictionary.MergedDictionaries> 
            <!-- Dummy Style, anything you won't use goes --> 
            <Style TargetType="{x:Type Rectangle}" /> 
        </ResourceDictionary> 
    </Application.Resources> 
</Application>   

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Caroline Martin

    Caroline Mar

    19 EYLÜL 2008
  • DavidParody

    DavidParody

    17 EKİM 2009
  • magnum33563

    magnum33563

    8 NİSAN 2011