FeatureList's menuitem in a separate class

1314
0
05-20-2011 12:49 AM
BerendVeldkamp
Occasional Contributor II
Hi,

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);
    e.FeatureListBox.MenuItems.Add(item);
}


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)
    {
        base.OnInitialized(e);
        Command = new RoutedUICommand("ClickMe", "ClickMeCommand", GetType());
        CommandTarget = _listBox;

        IsVisibleChanged += ItemIsVisibleChanged;

        var binding = new CommandBinding(Command);
        binding.Executed += BindingExecuted;
       
        _listBox.CommandBindings.Add(binding);
    }

    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