Reputation: 175
Lets say I got a CellContentTemplate
(of a column in a DataGrid
), and I define its DataTemplate
inline:
<Column.CellContentTemplate>
<DataTemplate>
</DataTemplate>
</Column.CellContentTemplate>
Is there a difference in terms of memory usage in comparison to referencing by StaticResource
to pre-defined DataTemplate
?
After all the content of the DataTemplate
is copied either way.
DataTemplate
has TextBlock
with Foreground
of "Green" in it. Does this "Green" brush is reused from row to row if I reference to DataTemplate
by StaticResource
or is it copied?Upvotes: 1
Views: 355
Reputation: 169210
The DataTemplate
itself will only be created once regardless of whether you create it as a reuasable resource or inline. So there is no difference in terms of memory usage unless you create another instance of the DataGrid
. Then there will be another instance of the inline DataTemplate
created.
Let's say this
DataTemplate
hasTextBlock
withForeground
of "Green" in it. Does this "Green" brush is reused from row to row if I reference toDataTemplate
byStaticResource
or is it copied?
The string "Green" that you defined in your XAML markup is resolved to Brushes.Green
which is a static property of the Brushes
class that returns the same cached and frozen brush each time.
Upvotes: 3