wpfprismurimefpack-uri

Prism v4, MEF, WPF - Using proper Uri for module graphic


My solution's structure is:

enter image description here

CI.Frontier.Classic contains a MEF module. My application uses the RibbonWindow control, and the modules define what menu items should be created. I can successfully add a button to the ribbon control from the CI.Frontier.Classic module, however, I cannot figure out the proper Uri to ClassicFrontierToopTip.png

Heres the code in FrontierClassic.cs that creates the tab, button and attempting to set the ribbon ToolTipImage

public void CreateMenuItems()
{
    TabData tabData = new TabData("Legacy");

    GroupData groupData = new GroupData("Internal");
    tabData.GroupDataCollection.Add(groupData);

    ButtonData classicFrontierBtn = new ButtonData()
    {
        Label = "Classic Frontier",
        ToolTipTitle = "Classic Frontier",
        ToolTipDescription = "Open Classic Frontier",
        ToolTipImage = new Uri("./Graphics/ClassicFrontierToolTip.png", UriKind.Relative)
    };
    classicFrontierBtn.Command.RegisterCommand(new DelegateCommand(LoadFrontierView));


    groupData.ControlDataCollection.Add(classicFrontierBtn);

    _ribbonService.AddTab(tabData);
}

This Uri doesn't work as the tooltip does not display. Can I use the UriKind.Relative or should I be using some sort of "pack uri"?


Solution

  • The robust approach would be to leverage the pack syntax...

    new Uri("pack://application:,,,/CI.Frontier.Classic;component/Graphics/ClassicFrontierToolTip.png", UriKind.Absolute);