This is a migrated thread and some comments may be shown as answers.

Loading RadMenuItems on demand asynchronously...

2 Answers 72 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 03 Feb 2011, 07:32 PM
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 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
answered on 03 Feb 2011, 10:47 PM
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:RadDropDownButton.DropDownContent>
      <Grid>
         <telerik:RadContextMenu x:Name="rcm"/>
         <telerik:RadBusyIndicator x:Name="bi" IsBusy="{Binding HasItems, Converter={StaticResource FlipBoolConverter}, ElementName=rcm}" />
      </Grid>
</telerik:RadDropDownButton.DropDownContent>
        </telerik:RadDropDownButton>

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.ContextMenu>
          <telerik:RadContextMenu x:Name="rcm2" Width="240" Height="280" Placement="Bottom">
          </telerik:RadContextMenu>
     </telerik:RadContextMenu.ContextMenu>
</ToggleButton>
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.
0
Konstantina
Telerik team
answered on 08 Feb 2011, 10:35 AM
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.

Greetings,
Konstantina
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Menu
Asked by
Rob
Top achievements
Rank 1
Answers by
Rob
Top achievements
Rank 1
Konstantina
Telerik team
Share this question
or