簡體   English   中英

在Silverlight 3中的generic.xaml中使用MergedDictionaries

[英]Using MergedDictionaries in generic.xaml in Silverlight 3

在WPF中,通過將標記保存在themes文件夾中的單獨XAML文件中,然后使用MergedDictionaries將它們導入generic.xaml,可以為多個用戶控件組織XAML:

<ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="MyFirstControl.xaml" />
        <ResourceDictionary Source="MySecondControl.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

隨着Silverlight 3 beta的推出引入了合並字典支持,似乎可以對Silverlight用戶控件做同樣的事情。 但是盡管在merge.xaml中嘗試了合並字典文件的構建操作的所有組合以及源引用的相應語法,但我似乎無法使其工作。

還有其他人試過嗎? 有誰知道這是否可能,如果是,我做錯了什么?


好的 - 所以在經過大量的測試項目之后,在WPF中獲取工作樣本並將XAML和C#代碼移到Silverlight 3並且它仍然失敗,我完全卸載並重新安裝所有Silverlight 2位和所有Silverlight 3 beta位和終於讓事情奏效了。

我只能假設我以某種方式最終安裝了錯誤的測試版 - 我不知道但是看起來我仍然在Silverlight 2運行時運行,盡管顯然安裝了版本3運行時。

感謝Jared看看事情並檢查SL3團隊......感謝Amy DullardShawn Wildermuth在同一台機器上生成運行Silverlight 2和3的指令和批處理文件。

我剛剛在用戶控件中嘗試了以下操作並且它有效:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="ResourcesA.xaml" />
            <ResourceDictionary Source="ResourcesB.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>
<StackPanel>
    <Rectangle Width="100" Height="100" Fill="{StaticResource ResAColor}" />
    <Rectangle Width="100" Height="100" Fill="{StaticResource ResBColor}" />
</StackPanel>

但是你特別提到generic.xaml。 你有什么問題?

- 編輯

根據其他評論,我與SL3團隊進行了交談,得到了以下答案:

使用generic.xaml作為資源編譯並使用完整資源語法,對我有用。 有一個錯誤,無法在generic.xaml(31783)中使用Source的相對URI,但非相對表單應該可以正常工作

<ResourceDictionary Source='/SilverlightClassLibrary1;component/CustomControl.xaml'/>

在generic.xaml中,將generic.xaml和CustomControl.xaml的構建操作修改為Resource。 讓我知道如果還有麻煩 - 如果你得到一個復制品,我可以看看它。

這有幫助嗎?

如果MySecondControl.xaml使用來自MyFirstControl.xaml的資源,那么將它們添加到generic.xaml的ResourceDictionary的順序無關緊要。 你需要冗余包括MyFirstControl.xamlMySecondControl.xaml MySecondControl.xaml應包含:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source='/MyControls;component/Themes/MyFirstControl.xaml'/>
</ResourceDictionary.MergedDictionaries>
<!-- ... Contents of MySecondControl.xaml -->

我剛剛解決了這個問題。 ResourceDictionaries支持MergedDictionaries,但對於使用Generic.xaml的自定義模板化控件,Generic.xaml不支持MergedDictionaries。 所以有兩種選擇:(1)你要么將所有模板都堆成Generic.xaml; 或者(2)創建YourOwnDictionary.xaml,將所有單獨的詞典合並到YourOwnDictionary.xaml中,並從usercontrols和pages引用YourOwnDictionary.xaml。 這似乎是早期Silverlight版本不支持合並字典的功能/錯誤。

暫無
暫無

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

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