문제

I am porting a Desktop WPF application to WinRT and I'm facing a little issue.

I had a ItemsControl and I had a context menu on every item to delete / edit the item.

I have been told that PopupMenu are not good in WinRT and I should use a AppBar.

I think I'm doing something wrong or I misunderstood that.

I thought that I could put that options on a AppBar and when I select an element, popup the bar and click where I need.

The problem is that the AppBar will show up when I right click on any part of my app, so that buttons will show up with an item selected.

So can I change the layout of the AppBar on different contexts (because it seems that Microsoft wants us to use AppBar as context menu without context capabilities) or only show it when I want via code?

Would be good to have a TopAppBar with some App-wide options and a BottomAppBar just for ListView's item context menu.

Or maybe I'm doing all this stuff wrong and I have to use another approach to put extra options on the Listview's items.

도움이 되었습니까?

해결책

You are thinking about this correctly. AppBar is the place where you should put all your non-essential and selection based commands.

The guidelines here and here suggest that they should be arranged as follows:

  • Navigation commands should be in TopAppBar
  • Commands related to selection should on the left side of BottomAppBar
  • The rest of page specific commands should be on the right side of BottomAppBar

Contextual commands should only be shown when a relevant item to that command is selected. For that purpose you should set Visibility of these commands accordingly. Also AppBar should open automatically when an item with contextual commands in it is selected. You can do that programmatically by setting its IsOpen property. You should also set it to sticky mode by via IsSticky property.

If you're using MVVM you can bind your viewmodel properties to all Button and AppBar properties mentioned above.

There's a CustomAppBar control available in WinRT XAML Toolkit. I haven't used it myself yet but it has a couple of extra features that might prove useful in your case.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top