Using MergedDictionaries in generic.xaml in Silverlight 3

穿精又带淫゛_ 提交于 2019-12-03 12:31:44

I just tried the following in a user control and it worked:

<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>

But you specifically mention generic.xaml. What sort of problem are you having?

-- EDIT

Based on the additional comments, I talked with the SL3 team and got the following answer:

Works for me, using generic.xaml compiled as a Resource, and using the full resource syntax. There is a bug on not being able to use relative URIs for the Source in generic.xaml (31783) but the non-relative form should work just fine

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

in generic.xaml, and modify the build actions for both generic.xaml and CustomControl.xaml to be Resource. Let me know if there’s still trouble—if you get a repro, I can take a look at it.

Does that help?

If MySecondControl.xaml uses a resource from MyFirstControl.xaml the order you add them to generic.xaml's ResourceDictionary won't matter. You'll need to redundantly include MyFirstControl.xaml in MySecondControl.xaml. MySecondControl.xaml should contain:

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

I just worked through this issue. ResourceDictionaries do support MergedDictionaries, but for custom templated controls using Generic.xaml, Generic.xaml does not support MergedDictionaries. So there are two choices: (1) you either pile all your templates into Generic.xaml; or (2) you create YourOwnDictionary.xaml, merged all of your separate dictionaries into YourOwnDictionary.xaml, and reference YourOwnDictionary.xaml from usercontrols and pages. This appears to be a feature/bug from earlier Silverlight versions not supporting merged dictionaries.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!