Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4121906
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:24:46+00:00 2026-05-20T23:24:46+00:00

I’m in the process of learning the Prism framework and I’ve come along way

  • 0

I’m in the process of learning the Prism framework and I’ve come along way already. But I was wondering about how to create toolbars (and context menus) where each module can register their own buttons.

For this example I want all buttons to reside in the same ToolBar control which is located in my Shell. The ToolBars ItemsSource binds to a ToolBarItems property of type ObservableCollection<FrameworkElement> in the view model. Elements can be added to this collection using a ToolBarRegistry service. This is the ViewModel:

public class ShellViewModel
{
    private IToolBarRegistry _toolBarRegistry;
    private ObservableCollection<FrameworkElement> _toolBarItems;

    public ShellViewModel()
    {
        _toolBarItems = new ObservableCollection<FrameworkElement>();
        _toolBarRegistry = new ToolBarRegistry(this);
    }

    public ObservableCollection<FrameworkElement> ToolBarItems
    {
        get { return _toolBarItems; }
    }
}

Note that the collection of type FrameworkElement will be refactored to be of a more concrete type if this turns out to be the correct solution.

My ToolBarRegistry has a method to register image buttons:

public void RegisterImageButton(string imageSource, ICommand command)
{
    var icon = new BitmapImage(new Uri(imageSource));

    var img = new Image();
    img.Source = icon;
    img.Width = 16;

    var btn = new Button();
    btn.Content = img;
    btn.Command = command;

    _shellViewModel.ToolBarItems.Add(btn);
}

I call this method from my OrderModule and the buttons show up correctly. So far so good.

The problem is how I can control when these buttons should be removed again. If I navigate to a view in another module (and sometimes another view in the same module), I want these module-specific buttons to be hidden again.

Do you have any suggestions on how to do this? Am I approaching this problem the wrong way, or can I modify what I already have? How did you solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:24:46+00:00Added an answer on May 20, 2026 at 11:24 pm

    I would not insert Button instances in the ObservableCollection. Think about this approach instead:

    Create ViewModel for the toolbar buttons

    class ToolBarButtonViewModel : INotifyPropertyChanged
    {
        // INotifyPropertyChanged implementation to be provided by you
    
        public string ImageSource { get; set; }
        public ICommand Command { get; set; }
        public bool IsVisible { get; set; }
    }
    

    Then of course change the type of ToolBarItems to a collection of these.

    In your ShellView, add a DataTemplate for ToolBarButtonViewModel and bind the ItemsSource of whatever your toolbar control is to the collection of ViewModels, for example:

    <DataTemplate>
        <Button Command="{Binding Command}">
            <Button.Content>
                <Image Source="{Binding ImageSource}" />
            </Button.Content>
        </Button>
    </DataTemplate>
    

    You can now bind Button.Visibility to IsVisible with a BooleanToVisibilityConverter to solve your immediate problem.

    As an added bonus, you can also:

    • Change the visual appearance of the toolbar buttons entirely from XAML
    • Bind any property of the visual tree for a toolbar button to corresponding properties on the ToolBarButtonViewModel

    Update

    The mechanism for enabling/disabling buttons depends on specifics of your application. There are many options — here are a few (keep this chart in mind while reading):

    • Implement INavigationAware in your Views or ViewModels and enable/disable buttons as required
    • Attach handlers to the events of IRegionNavigationService of the region(s) of interest and have the handlers enable or disable buttons
    • Route all navigation through your own code (CustomNavigationService) and decide what to do inside it
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in the process of learning more about C# and am wondering how to
I am in the process of learning about big oh notation. For the code
I'm in the process of learning C++. But there's so much more that I
I am in the process of learning the Yii Framework. I have been following
I'm in the process of learning Javascript and I'm trying to create a simple
I'm in the process of learning about servlet containers and web apps based on
i'm daily in the process of learning new things about Rails (started learning 2
In the process of learning C... trying to create a function for some test
Im in the process of learning regular expressions but still cant really wrap my
I'm in the process of learning Entity Framework/MVC 4, and started following some tutorials

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.