开发者

Error trying to freeze a Rectangle filled with a BitmapCacheBrush

开发者 https://www.devze.com 2023-04-11 01:49 出处:网络
I\'m trying to Freeze a BitmapCacheBrush, but when I call Freeze it errors stating it can\'t be frozen.

I'm trying to Freeze a BitmapCacheBrush, but when I call Freeze it errors stating it can't be frozen.

What I'm trying to do is fill a Rectangle with a BitmapCacheBrush and then at some point, Freeze it so I can then animate the Rectangle and reuse the source Grid for something else (whilst animating the Rectangle).

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="50*"></RowDefinition>
        <RowDefinition Height="50*"></RowDefinition>
    </Grid.RowDefinitions>

    <Grid x:Name="LISTING">
        <Grid.CacheMode>
            <BitmapCache RenderAtScale="1" SnapsToDevicePixels="True"/>
        </Grid.CacheMode>
        <Rectangle x:Name="Rectangle1" Fill="Red" />

        <Label Content="Test" FontSize="20" Foreground="Black" />
        <But开发者_C百科ton x:Name="Button1" Click="Button1_Click"/>
    </Grid>

    <Rectangle Grid.Row="1" x:Name="Rectangle2" >
        <Rectangle.Fill>
            <BitmapCacheBrush x:Name="BMCB" Target="{Binding ElementName=LISTING}"/>
        </Rectangle.Fill>
    </Rectangle> 
</Grid>

In my test I am trying to see if I can Freeze the BMCB BitmapCacheBrush when the button is clicked, then as a test I want to hide the button and still see the bottom rectangle intact.

I'm wanting to use BitmapCacheBrush for the performance aspect.

Is this even possible?

Thanks Ben


I would say No: But my only source to prove that is the Freezable documentation in the msdn, which says:

A Freezable can't be frozen if any of the following are true:

  • It has animated or data bound properties.
  • It has properties set by a dynamic resource.
  • It contains Freezable sub-objects that can't be frozen.

So i guess you can't freeze it because of your Target="{Binding ElementName=LISTING}" binding.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号