Inherit from Selector RRS feed

  • Question

  • I am about to create a custom control that inherits from Selector then the compiler tells me

    Error    4    The type 'Windows.UI.Xaml.Controls.Primitives.Selector' has no constructors defined

    Looks like Selector's constructor is defined as protected internal.  Why?

    Saturday, August 10, 2013 11:21 PM


All replies

  • The Selector was not implemented to be publically inheritable. I don't have any details on why.


    Sunday, August 11, 2013 1:07 AM
  • Yea, I guessed so.  I just wanted to complain.  It would be a useful class to be able to inherit from.
    • Proposed as answer by AtmosSA Monday, August 12, 2013 1:29 PM
    • Unproposed as answer by AtmosSA Monday, August 12, 2013 1:30 PM
    Sunday, August 11, 2013 1:48 AM
  • You can inherit from Combobox and ListView / ListBox.

    Customize these control's style to your liking. (In my case I edited a combobox to have an edible TextBox inside it)


    Drag a Combobox or ListBox from your toolbox onto the page. (Try a blank page on a test solution first)

    Right Click on it > Edit Template > Edit a copy.

    This will copy the control style template to your blank page, now you can edit it to your liking.

    Tip : Don't delete any 'parts' out of the style, instead change the Visibility to Collapsed. Otherwise errors might occur.


    Now you can override the "OnApplyTemplate" method in your custom control to grab and write custom code for it.

    In my case I created a TextBox inside the template, I can get a reference to this TextBox by using: GetTemplatedChild("nameOfTextBox") as TextBox;

    Now you can hook up events and white code to use the custom control.


    This answer might not be perfect, but it definitely helps if you want the standard controls extended just a bit.

    Regards Atmos


    • Edited by AtmosSA Monday, August 12, 2013 1:39 PM Typo
    Monday, August 12, 2013 1:39 PM