Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Bind a UserControl string array property to containing window

Bind a UserControl string array property to containing window

Scheduled Pinned Locked Moved WPF
data-structurescsharphtmldebugging
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jean Louis Leroy
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • J Jean Louis Leroy

      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

      J Offline
      J Offline
      Jean Louis Leroy
      wrote on last edited by
      #2

      Ok I found the solution here: use a List instead of a string[].

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups