Freigeben über


Developer test case, customer win! [Using ContextMenu to implement SplitButton and MenuButton for Silverlight (or WPF)]

**

This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of dlaa.me.

See you there!

Comments

  • Anonymous
    May 02, 2010
    The comment has been removed

  • Anonymous
    May 03, 2010
    myCollections, According to the MSDN documentation, WPF doesn't allow a null parameter to TransformToVisual: http://msdn.microsoft.com/en-us/library/system.windows.media.visual.transformtovisual.aspx An alternative would be to walk up the visual tree to find the top-most Parent and pass that instead - that should work on WPF as well as Silverlight. I've added a note to my TODO list to look into this, but please let me know if you give it a try and have any luck. :) Thanks!

  • Anonymous
    June 02, 2010
    Have you got my response?

  • Anonymous
    June 02, 2010
    Delay, what a great control, thanks! But the posistioning of the menu is not perfect is the browser's zoom is set other than 100% or if you use it in OOB mode and your desktop DPI is other than 100%. Do you have any hint how to fix this? Thanks, John

  • Anonymous
    June 03, 2010
    John, Sorry about the trouble! As I mention above, SplitButton was mainly a test case. I tried to catch some of the obvious edge cases, but deliberately didn't do them all. :) I think I actually knew about the browser zoom issue at the time, but didn't want to complicate things too much since we still hadn't shipped at that point and there was plenty else to do. I've added a note to my TODO list to look into this - perhaps as part of the work to address the WPF-specific issue another commenter raised! For the time being, you might find some inspiration for fixing or addressing this here: blogs.msdn.com/.../the-code-not-taken-comparing-two-ways-of-creating-a-full-size-popup-in-silverlight-then-picking-the-best.aspx Hope that helps!

  • Anonymous
    June 13, 2010
    David, Great control, but hard to find ... any chance you will post it on Codeplex? regards

  • Anonymous
    June 14, 2010
    Thomas, Thanks! Some of my stuff ends up on CodePlex, but usually because someone else is willing to take care of the project creation/management/overhead. :) If you're interested in doing this, contact me privately and we can chat!

  • Anonymous
    June 14, 2010
    Follow-up: I addressed the issues raised in the comments above and posted the following: blogs.msdn.com/.../splitbuttoning-hairs-two-fixes-for-my-silverlight-splitbutton-menubutton-implementation-and-true-wpf-support.aspx (The link to the ZIP is the same for both posts, so downloading from here also gets you the latest code.)

  • Anonymous
    April 20, 2011
    This is a great control. How do I template the context menu item. Because I want to set the source through code like below eg. <pre> ObservableCollection<object> PredefinedColors = new ObservableCollection<object>      {         new MyColor{ColorName = "Aliceblue", ColorCode = 0xFFF0F8FF},         new MyColor{ColorName = "AntiqueWhite", ColorCode = 0xFFFAEBD7},         new MyColor{ColorName = "Aqua", ColorCode = 0xFF00FFFF},         new MyColor{ColorName = "Aquamarine", ColorCode = 0xFF7FFFD4} } Mysplitcutton.ButtonMenuItemsSource = PredefinedColors ; <pre>

  • Anonymous
    April 21, 2011
    Fred, Thanks! :) So if you look at the default Style/Template for SplitButton/MenuButton (in ThemesGeneric.xaml), you'll see a ContextMenu in there. You should therefore be able to provide a custom Template that includes any ContextMenu customizations you want to make. Hope this helps!