Hello, I have a UserControl that exposes a Selection property:
public partial class FeatureSelectionControl : UserControl
{
public string\[\] Selection
{
get { return (string\[\])GetValue(SelectionProperty); }
set { SetValue(SelectionProperty, value); }
}
public static readonly DependencyProperty SelectionProperty =
DependencyProperty.Register("Selection", typeof(string\[\]), typeof(FeatureSelectionControl), new UIPropertyMetadata(new string\[\] { }));
I want to use it in a window and bind the control's property to one of the window's properties:
Code behind:
public partial class WindowCounterpartyGroupRiskReview : Window
{
public WindowCounterpartyGroupRiskReview()
{
CustomerGroups = new string[] { };
InitializeComponent();
}
public string\[\] CustomerGroups { get; set; }
This crashes with a "first chance exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll Additional information: Object reference not set to an instance of an object". STack trace is:
PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ProvideValueFromMarkupExtension(System.Windows.Markup.MarkupExtension markupExtension = null, object obj = {System.Windows.Markup.BamlCollectionHolder}, object member = null) + 0x52 bytes
PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ReadPropertyArrayEndRecord() + 0x5f bytes
PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ReadRecord(System.Windows.Markup.BamlRecord bamlRecord) + 0x636 bytes
PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.Read(bool singleRecord = false) + 0x1c bytes
PresentationFramework.dll!System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment() + 0xc9 bytes
PresentationFramework.dll!System.Windows.Markup.TreeBuilder.Parse() + 0xf bytes
PresentationFramework.dll!System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext, object parent, bool closeStream) + 0xc7 bytes
PresentationFramework.dll!System.Windows.Application.LoadComponent(object component, System.Uri resourceLocator) + 0x16e bytes
CRRT.exe!CRRT.WindowCounterpartyGroupRiskReview.InitializeComponent() Line 1 + 0xb bytes C#
However, whe