简体   繁体   English

昂贵的静态资源

[英]Costly StaticResource

I have a CheckBox style that I use over multiple UserControl s, ~100 in each one. 我有一个CheckBox样式,可以在多个UserControl使用,每个〜100。 Then, when I try and use these UserControl s, it can take several seconds to load. 然后,当我尝试使用这些UserControl ,可能需要花费几秒钟来加载。 I have tracked it down to my style using an image, as when I comment it out, everything works just fine. 我已经使用图像将其追踪到我的风格,因为当我注释掉它时,一切都很好。

Is there a way to load the image in once, then use that local copy in the styles? 有没有办法一次加载图像,然后以样式使用该本地副本? Or maybe do that with the whole style in each of the UserControl s? 还是在每个UserControl中使用整个样式?

This is the style, 这是风格

<Style x:Key="MyCheckBoxStyle" TargetType="CheckBox">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="CheckBox">
                <Grid>
                    <Grid VerticalAlignment="Top">
                        <Image Source="/Images/Unchecked.png">
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

You could create a BitmapImage once and reuse it: 您可以一次创建一个BitmapImage并重用它:

<BitmapImage x:Key="UncheckedBitmap" UriSource="/Images/Unchecked.png"/>
...
<Image Source="{StaticResource UncheckedBitmap}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM