FeatureList's menuitem in a separate class

05-20-2011 12:49 AM
Occasional Contributor II

I followed the GlobalFeatureMenuCustomizationExtension sample to add a menuitem to the FeatureListBox. So far everything is fine. To avoid cluttering my extension's class, I tried to put all the menuitem's code in a separate class, and although it still works, the menuitem's caption now has an offset of a few pixels to the left, see the attached image.

I'm sure I'm missing something obvious, but I can't seem to find what it is. Please help!

Here's the Extension's code:

private void FeatureListBoxCreatingFeatureListBoxMenuItems(object sender, CreatingFeatureListBoxMenuItemsEventArgs e)
    var item = new TestMenuItem(e.FeatureListBox);

And here's the MenuItem's code:

public class TestMenuItem : MenuItem
    private readonly FeatureListBox _listBox;

    public TestMenuItem(FeatureListBox listBox)
        _listBox = listBox;

    protected override void OnInitialized(EventArgs e)
        Command = new RoutedUICommand("ClickMe", "ClickMeCommand", GetType());
        CommandTarget = _listBox;

        IsVisibleChanged += ItemIsVisibleChanged;

        var binding = new CommandBinding(Command);
        binding.Executed += BindingExecuted;

    static void BindingExecuted(object sender, ExecutedRoutedEventArgs e)
        // Execute command

    private void ItemIsVisibleChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
        // Determine if menuitem can be enabled
0 Kudos
0 Replies