Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is more efficient {X:Static Class.Default} or {StaticResource Class}?

Tags:

xaml

Suppose I have class I want to reference in XAML.

public class MyConverter
{
  public static readonly MyConverter Default = new MyConverter();
  ...
};

And then in XAML I can reference it either

<Label Content="{Binding Text,Converter={x:Static local:MyConverter.Default}"/>

or

<local:MyConverter x:Key="MyConverter"/>
...
<Label Content="{Binding Text,Converter={StaticResource local:MyConverter}"/>

Which way is more efficient?

like image 514
AlexK Avatar asked Oct 12 '22 10:10

AlexK


1 Answers

I doubt anything here will be more effecient than other but the key difference here is what is actually going on:

  1. In first approach you're referencing static field of class MyConverter
  2. In second case you're creating an instance of MyConverter and using it.

I believe first one might couple percents faster (or what do you mean by efficient?) but this difference won't give you much profit. I would choose option #1 if you already have a static field. Also as far as I remember x:Static still is not available in Silverlight.

like image 56
Snowbear Avatar answered Oct 26 '22 23:10

Snowbear