Opening a listpicker programatically

11 posts, 1 answers
  1. Nathan
    Nathan avatar
    8 posts
    Member since:
    Oct 2011

    Posted 26 Oct 2011 Link to this post

    I have noticed there is not a way to do this...is there?  Such as, RadListPicker.open()?
    I'll explain my purpose and maybe I'm just missing something.
    I would like to have a button of some kind, like a + symbol, open a popup listpicker control.  Then based on the item selected, populate a stackpanel of textblocks.
    But the listpicker would be unseen otherwise.  Would a different control work better?  Is there a way to open the listpicker programatically?

    Thanks for the support!
  2. Answer
    Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 26 Oct 2011 Link to this post

    Hello Nathan,

    You can use the RadListPicker.IsExpanded property for your purpose.

    Greetings,
    Deyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Nathan
    Nathan avatar
    8 posts
    Member since:
    Oct 2011

    Posted 27 Oct 2011 Link to this post

    Hello Telerik. Had a follow up question: I have noticed that when I subscribe the selectionchanged event to teh RadListPicker (after adding the items) , it fires the event.  After some testing, I realized that I don't have to add anything to it.  Merely the act of subscribing the event fires it.  See below.

    Example-
    public PageConstructor()
    {
    InitializeComponent();
    test.SelectionChanged += new SelectionChangedEventHandler(test_SelectionChanged);
    }
    void test_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    throw new NotImplementedException();
    }

    it will hit the NotImplementedException on page load in debugging. Am I missing something here? I haven't added anything to the RadListPicker. What you see here is the exact code that fires it. There is no databinding or items being added. Nothing was clicked, only page load.

    Am I just totally missing something here?
    Thanks for the help in the previous question!

    UPDATE: as a workaround, I check for the IsExpanded property to see if it's been opened to get the value chosen.  If true, I go ahead and do my logic.
    Would still like to know an answer in general on why this event fires on subscription, but this is a good workaround.
  5. Georgi
    Admin
    Georgi avatar
    296 posts

    Posted 31 Oct 2011 Link to this post

    Hi Nathan,

    Thanks for getting back to us.

    This behavior is by design. The listpicker will always try to select its first item if no user selection is defined. Hence, the SelectionChanged event is raised upon control's loading, when this default selection is performed.

    Does this make sense, what is your opinion in this case - should we raise the event, letting the user know that the selection is changed or we should make it silently?


    Regards,
    Georgi
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Nathan
    Nathan avatar
    8 posts
    Member since:
    Oct 2011

    Posted 01 Nov 2011 Link to this post

    Well, I suppose I could understand in the case of the databinding.  It does make some sense in certain cases.  But at event subscription time?  I cannot think of a time where this would be a welcome time to fire the event, especially when no data has been bound.  It's your call though and I've certainly found work-arounds for my particular case.
    Thanks for asking for my input!  Keep up the good work!
  7. Georgi
    Admin
    Georgi avatar
    296 posts

    Posted 02 Nov 2011 Link to this post

    Hi Nathan,

    Thanks for getting back to us and for your input.

    The event is not raised at the same moment when you subscribe for it. It is raised upon control's loading phase, which occurs when the page is about to be displayed. So, if you add an event handler in the constructor, you will get the initial SelectionChanged. If you however hook page's Loaded event and add the handler there you will not get the initial SelectionChanged because the control itself is already loaded and has performed its default selection.

    I hope this helps. Do not hesitate to contact us with any question/problem you may have with our tools.

    All the best,
    Georgi
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Nathan
    Nathan avatar
    8 posts
    Member since:
    Oct 2011

    Posted 03 Nov 2011 Link to this post

    Ah, OK.  I see what you are saying.  Thanks for claryfing the order of events!
  9. Laurensius
    Laurensius avatar
    17 posts
    Member since:
    Jan 2014

    Posted 06 Mar 2014 in reply to Deyan Link to this post

    hi sorry for bringing this post up but can you tell me how to use this RadListPicker.IsExpanded for your situation? because i want to also showing radlistpicker fullscreen popup when i tap my image
  10. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 06 Mar 2014 Link to this post

    Hi Laurensius,

    Doesn't simply setting the IsExpanded to true or false solve your problem?

    Regards,
    Deyan
    Telerik

    DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

  11. Laurensius
    Laurensius avatar
    17 posts
    Member since:
    Jan 2014

    Posted 06 Mar 2014 in reply to Deyan Link to this post

    hmm what i mean is where i should put that in c#? do i need to put listpicker in my xaml? 
  12. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 07 Mar 2014 Link to this post

    Hello Laurensius,

    I am not quite sure that I correctly understand your question.

    You need to have a list picker instance on your page with assigned x:Name property to be able to access it in the code-behind file and call its methods or properties.

    Regards,
    Deyan
    Telerik

    DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

Back to Top
DevCraft banner