Loading RadMenuItems on demand asynchronously...

3 posts, 0 answers
  1. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 03 Feb 2011 Link to this post

    In my application, I have a datagrid where one column contains a radmenu (that we are using as a grid row context menu essentially).  We want to asynchronously retrieve the context menu items when the user attempts to open the context menu.  Is there an example of this?  I haven't been able to find one in the limited searching I've done.  Or is there a suggested method for accomplishing this?  Another reason we don't want to populate the context menu until the user opens it is because the permissions for each datagrid row will actually be different so each context menu will contain different options.
  2. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 03 Feb 2011 Link to this post

    I have *solved* my problem in so far as I can get past it for now...  For those who are interested....

    I came up with two possibilities - a) a ToggleButton/RadContextMenu or b) a RadDropDownButton.  Initially I started with the RadDropDownButton because I was more familiar with it and I liked that it allowed me to put any content instead of just a context menu.

    So I ended up with this:
    <telerik:RadDropDownButton DropDownHeight="300" DropDownWidth="300" DropDownOpening="RadDropDownButton_DropDownOpening" DropDownOpened="RadDropDownButton_DropDownOpened" DropDownClosed="RadDropDownButton_DropDownClosed" >
             <telerik:RadContextMenu x:Name="rcm"/>
             <telerik:RadBusyIndicator x:Name="bi" IsBusy="{Binding HasItems, Converter={StaticResource FlipBoolConverter}, ElementName=rcm}" />

    Ignore the "RadDropDownOpening", "RadDropDownOpened", and "RadDropDownClosing" events for now.  All they do is "lazily" (by that I mean asynchoronously) set the ItemsSource for the context menu...  By binding the IsBusyIndicator to the HasItems property, I essentially have what i wanted and it worked just fine EXCEPT for the fact that the dropdown wouldn't close when I clicked on an item.  I can't bring myself to add a handler to the ItemClick to close the dropdown... so I looked for another solution.
    <ToggleButton x:Name="tb" IsChecked="{Binding IsOpen, ElementName=rcm2, Mode=TwoWay}" Checked="tb_Checked">
              <telerik:RadContextMenu x:Name="rcm2" Width="240" Height="280" Placement="Bottom">
    The second option is only slightly different in that the context menu item click will automatically close the popup (and uncheck the toggle).  But what about the busy indicator you ask?  AHA.  Add a custom style to the Context Menu and you're done...  Inside the template for the context menu, I have added a busy indicator and simply changed the binding to:
    <telerik:RadBusyIndicator IsBusy="{Binding HasItems, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource FlipBoolConverter}}" />

    And it seems to work just fine...  We'll see if I have any problems later on after I put it into the project but so far so good.
  3. Konstantina
    Konstantina avatar
    2332 posts

    Posted 08 Feb 2011 Link to this post

    Hello Rob,

    Thank you for sharing your solution.

    We are glad that you have found a solution yourself. For further reference I can suggest you to go through our online documentation here.

    Please do not hesitate to contact us again if you have any other questions about our controls.

    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top