English 中文(简体)
合并和资源调查
原标题:MergedDictionaries and Resource lookup

i 存在资源字典和合并字典的问题,特别是在资源评价业绩方面。 在经过一些绩效测试后,发现资源开发商。 Merged 剂量最多的是注射器(由ANTS简介仪检查)。 我们拥有大约300个资源词典xamls,其中很多人正在使用合并字典,以“包括”其他风格。 得到的“MergedDictionaries”就占我们申请的1 000万次点击。 因此,我的猜测是,我们与整个资源独裁者一道做了完全错误的事情。 因此,我试图重心一切,并想设法消除所有合并的独裁者。

现在谈谈实际问题。 我试图排除合并的独裁者,但我失败了。 我的理解是,当你使用法定资源时,调查需要现在之前确定的资源。 我举了一个简短的例子:

One main project and one custom control library.

海关控制图书馆有2个Xamls。

<!-- Colors.xaml -->
<ResourceDictionary [stripped namespaces] >
    <SolidColorBrush x:Key="myColor" Color="Green"/>
</ResourceDictionary>

<!-- Templates.xaml -->
<ResourceDictionary [stripped namespaces]>
    <ControlTemplate x:Key="myTemplate" TargetType="Button">
        <Rectangle Fill="{StaticResource myColor}"/>
    </ControlTemplate>
</ResourceDictionary>

现在,在主要项目中,Maindow.xaml认为情况如此。

<Window x:Class="ResourceTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/ResourceTestLib;component/Themes/Colors.xaml"/>
                <ResourceDictionary Source="/ResourceTestLib;component/Themes/Template.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Button Template="{StaticResource myTemplate}"/>
    </Grid>
</Window>

这是理想的目标,但不幸的是,由于无法找到“米科罗”资源,这一坠毁事件。 我当然知道如何加以固定,在模板中添加一个合并的词典。 xaml and reference Colors. xaml,但我总是认为,资源是根据逻辑树和要素的资源来审视的。 我的理解是;布顿是建立起来的;试图寻找模板;试图看看看看看肤色,不依靠自己的资源,走路和使用窗户资源。

It seems that i m wrong. So i hope someone can shed some light on this for me. We make heavy use of WPF and despite of this we accomplished a lot with it, but because of some wrong learned behaviour in the beginning, our performance is pretty bad just because of the resource lookup. Any help would be greatly appreciated

Thanks in advance Best regards Nico

最佳回答

当然,我不想回答我自己的问题,但我猜想,许多人可能陷入这一困境,我希望把我们目前的解决办法作为考虑的一个选择。

Like I said before, we have a lot of XAMLs, around ~300 for all different kinds of things like Shared Resources (Brushes, Colors) but also many XAMLs containing different DataTemplates, Styles for controls and also for Custom Controls. In the beginning, this approach of having a lot of XAMLs was reasonable for us because we do the same with our classes and keep them small and organized. Unfortunately, WPF doesn t like that. The more ResourceDictionaries you have and the more you merge them via MergedDictionaries the worse your performance will get. The best advice I can give you is, use as few ResourceDictionary XAMLs as possible.

我们截了该子弹,把其中的许多子弹合并为一个巨型的XAML,事实上,我们现在这样做的是先使这两个世界保持最佳。 我们能够像我们所希望的那样,在几个制约因素之后,把他们编成一个巨头的XAML。 我们取得的成效显著提高。 在我的问题中,我写道,“11万次大罢工”......只是“预谋”我们的一个集会,我们已跌至200万次,而且整个工作都得到了更好的应用。

因此,最后。 不应将XAML资源视为汇编成册的源代码,而应将其理解为一种实际资源,一旦申报,即占用空间和性能。

Well, we had to learn that the hard way. I hope everyone reading this can improve their projects by learning from our mistakes.

问题回答

我倾向于在申请中只使用一名顾问以避免任何业绩问题。

为使XAML能够管理,我利用XAML地区视频演播室的原始材料,并总结一个区域的每一类资源。

  • Brushes
  • Text Styles
  • etc...

For this scenario, the plugin is an absolute life saver. http://visualstudiogallery.msdn.microsoft.com/3c534623-bb05-417f-afc0-c9e26bf0e177

Using SharedResourceDictionary instead of ResourceDictionary completely solved MergedDictionaries performance issue for me: http://www.wpftutorial.net/MergedDictionaryPerformance.html

Was any light shed on the resource lookup procedure? Why was "myColor" not found?

顺便说一句,我找到了工作方式——但是一种奇怪和不稳定的方式。 申请。 Xaml有这部法律,应当发现:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/ResourceTestLib;component/Themes/Colors.xaml"/>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/ResourceTestLib;component/Themes/Template.xaml"/> 
        </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary>
</ResourceDictionary.MergedDictionaries>

而另一方面,如果你将这一守则列入另一个XAML,那么你将把该守则列入申请。 xaml——尽管资源结构相同(与Snoop相比)。





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签