Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between using "Binding with StaticResource" and using "StaticResource directly" in WPF

Tags:

c#

.net

wpf

xaml

I have created a mycustomItemsPanel in App.Resources

<Application.Resources>
    <ItemsPanelTemplate x:Key="mycustomItemsPanel">
        .... Some code here
    </ItemsPanelTemplate>
</Application.Resources>

and providing this to a UIControl this way

<.... ItemsPanel="{StaticResource mycustomItemsPanel}" />

But I came to know that this can be provided as

<.... ItemsPanel="Binding Source={StaticResource mycustomItemsPanel}}" />

What is the difference between these?

like image 377
Nikhil Agrawal Avatar asked Jul 30 '12 09:07

Nikhil Agrawal


1 Answers

For one thing the binding will only be able on dependency properties, another would be that some objects behave differently when assigned as a Binding.Source, namely DataSourceProviders.

Common base class and contract for DataSourceProvider objects, which are factories that execute some queries to produce a single object or a list of objects that you can use as binding source objects.

The object provided by the DataSourceProvider then is used instead of the DataSourceProvider itself.

In this specific case there hence should be no practical difference.

like image 130
H.B. Avatar answered Nov 03 '22 23:11

H.B.