开发者

Context-sensitive layout - change visibility of set of WPF tools based on a combobox

I have a UI issue with layered editing where a different set of tools needs to be visible depending on the ComboBox selecting the layer and am stewing over the idiom to use. The tools should not be in a visible container.

The ComboBox selection is bound to a simple integer property in the ViewModel.

The alternatives I've been considering are mostly based around a series of StackPanel containers at the same location:

  1. Bind the StackPanels' visibility properties to a different ViewModel property for each, then have those visibility properties calculate based on the Combo's backing value. I will have to add some further notification to ensure they refresh when the Combo changes.
  2. Use a ValueConverter to bind StackPanels' visibility properties directly to the Combo selection
  3. Put the StackPanels in each of the TabItems in a TabControl and suppress any drawing of header, so the TabControl selection can be mapped directly to the Combo selection.
  4. Use a Selector subclass or just templating a Selector to开发者_StackOverflow中文版 get the behaviour of 3 without any baggage from TabControl.
  5. The approach I'm using for now - added a Click handler to the popup on which their visibility is supposed to depend and simply set the visibility of the different panels according to that popup's SelectedIndex. Very old-school but simple and easy to follow code.


I vote for #1. I know the WPF purists will say that this is a bit "old school" and there are better ways of handling it. But sometimes you just need some basic examples of old functionality and KISS is the best way to go about it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜