昂贵的StaticResource

时间:2016-11-17 23:06:22

标签: c# wpf xaml

我有一个CheckBox样式,我在多个UserControl上使用,每个样式约100个。然后,当我尝试使用这些UserControl时,可能需要几秒钟才能加载。我使用图像跟踪它的风格,就像我评论它一样,一切正常。

有没有办法一次加载图像,然后在样式中使用该本地副本?或者也许在每个UserControl s?

中使用整个风格

这是风格,

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

1 个答案:

答案 0 :(得分:0)

您可以创建一次BitmapImage并重复使用它:

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