let me know I am in the process of learning the prism structure and I have already come together. But I was thinking about how to create toolbars (and context menus), where each module can register its button.
For this example, I want all buttons to be located in the same toolbar control which is located in my shell. The toolbar itemsSource is the property of a
toolbar item in the
observation list & lt; Framework Element & gt; is built into a visual model. Elements can be added to this collection using a
ToolBarRegistry service, it is ViewModel:
public square ShellViewModel { Private IToolBarRegistry _toolBarRegistry; Personal observable collection & lt; Framework Element & gt; _toolBarItems; Public ShelvesModel () {_toolBarItems = New Observational Collection & lt; Framework Element & gt; (); _toolBarRegistry = new toolbarwid (this); } Public Observable Collection & lt; Framework Element & gt; ToolBarItems {get {return _toolBarItems; }}} Note that the collection of typeworkwork must be a more solid type again if this is the correct solution.
One way to register image buttons in my ToolBarRegistry is:
Registered Public Zero ImageButton (String ImageSource, ICMMand Command) {var icon = new bitmap image (new URI (image source)); Var img = new image (); Img.Source = icon; IMG Wideth = 16; Var BTN = New Button (); BTN Content = img; BTN Command = command; _shellViewModel.ToolBarItems.Add (btn); } I call this method from my order module and buttons appear properly. So far so good.
The problem is that how can I control when I should delete these buttons again. If I navigate a view in any other module (and sometimes in other modules in the same module), then I want to hide these module-specific buttons again.
Do you have any suggestions on doing this? Am I delivering this problem in a wrong way, or can I modify it already? How did you solve this problem?
I do not include the button in observable collection . Instead, think about this approach:
Create ViewModel for toolbar button class toolbar buttonviewmodel: INotifyPropertyChanged {// INotifyPropertyChanged implementation provided by you for public string ImageSource {get; Set; } Received the public ICommand command { Set; } Get Public Child Available (Receive; Set; }} Then definitely change ToolBarItems to this type of archive.
Add ToolBarButtonViewModel to your ShellView , DataTemplate and ItemsSource to whatever your The control of the toolbar is in the collection of ViewModels, for example:
& lt; Datatomplate & gt; & Lt; Button command = "{binding command}" & gt; & Lt; Button.Content & gt; & Lt; Image source = "{binding image source}" /> & Lt; /Button.Content> & Lt; / Button & gt; & Lt; / DataTemplate & gt; Now you can force the button. Specialty to isvizible to solve your immediate problem.
As an added bonus, you can also:
- Change the appearance of the toolbar buttons completely from XAML
- The mechanism depends on the attributes of your application:
ToolBarButtonViewModel On update
- There are several options - here are some (keep in mind when reading):
- Necessary Implement your view or view modules and enable / disable buttons
-
- Route all navigation through your own code (
CustomNavigationService ) and Decide what to do in this
Comments
Post a Comment