Nikhil Agrawal
Nikhil Agrawal

Reputation: 48568

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

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?

Upvotes: 9

Views: 915

Answers (1)

brunnerh
brunnerh

Reputation: 184506

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.

Upvotes: 3

Related Questions