nvonhertzen
Topic Author
Posts: 2
Joined: 20 Apr 2022, 15:26

Freezing brushes

20 Apr 2022, 15:31

I am trying to move some of our brushes from application resources to the views root elements resource dictionary. While doing this, I noticed that our animations that animate brushes no longer work as expected (instead of animating a single element, it animates every instance of an element referencing that brush). Reading through https://stackoverflow.com/questions/370 ... pf-objects it seems like this sort of mutable brushes is the way it is supposed to work, however I am now struggling to figure out how I can actually freeze these resource dictionaries/brushes. Looking through the Noesis source code, it seems like the reason the application resources worked is that it freezes the provided resource dictionary when provided, where as now the resources defined in the dictionaries are no longer frozen.

That stackoverflow post referenced a property that WPF supports to freeze the brushes with
ice:Freeze="True"
but that doesn't appear to be supported in Noesis? How can I get these brushes frozen (preferably directly through XAML) without having to rely on putting them into the application resources?
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Freezing brushes

21 Apr 2022, 00:04

We don't support the Freeze attribute yet, and unfortunately there is no other way to freeze a resource in xaml than defining it in the Application Resources.
I'm assigning the Freeze attribute request in our roadmap for the upcoming 3.1.5 version: #824

In the meantime you can create an attached property that can freeze the resource on the property changed callback:
<SolidColorBrush x:Key="redBrush" Color="Red" local:AttachedProps.Freeze="True" />
static void OnFreezeChanged(DependencyObject* dob, const DependencyPropertyChangedEventArgs& e)
{
  bool freeze = e.NewValue<bool>();
  Freezable* freezable = DynamicCast<Freezable*>(dob);
  if (freeze && freezable != nullptr && freezable->CanFreeze()) freezable->Freeze();
}

Who is online

Users browsing this forum: No registered users and 6 guests