Freezable Collection issue (appear null) as dependency property xaml
Hello,
We have created a Freezable collection of framework element to be able to create static collection as dependencyProperties like so :
C#:
usage in xaml:
However, Blend doesn't like this piece of code :
Thanks for all your work!
We have created a Freezable collection of framework element to be able to create static collection as dependencyProperties like so :
C#:
Code: Select all
public class ParameterCollection : FreezableCollection<ParameterViewData> { }
public class ParameterViewData : FrameworkElement { ... }
public class TextContentControl: ContentControl
{
public ParameterCollection TextParameters
{
get { return (ParameterCollection)GetValue(TextParametersProperty); }
set { SetValue(TextParametersProperty, value); }
}
public static readonly DependencyProperty TextParametersProperty = DependencyProperty.Register(nameof(TextParameters), typeof(ParameterCollection), typeof(TextContentControl),
new PropertyMetadata(null, OnTextParametersChanged));
}
Code: Select all
<common:TextContentControl >
<common:TextContentControl.TextParameters>
<common:ParameterViewData Key="Foo" Value="{Binding Holding.Tier}"/>
</common:TextContentControl.TextParameters>
</common:TextContentControl>
Is there anything I have forgot to do in order to be able to initialize this type in xaml?Error:Collection property 'TextContentControl'.'TextParameters' is null.
Thanks for all your work!
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Freezable Collection issue (appear null) as dependency property xaml
Hi, you need to set the property when the control is constructed:
Code: Select all
public class TextContentControl: ContentControl
{
public TextContentControl()
{
TextParameters = new ParameterCollection();
}
...
}
Re: Freezable Collection issue (appear null) as dependency property xaml
It worked. Thank you!
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Freezable Collection issue (appear null) as dependency property xaml
Great, thanks for the update.