Search code examples
xamlwindows-8winrt-xamlexpression-blendcustom-component

Custom Control with Multiple ContentPresenters


I am trying to implement a custom control which will show different content according to 3 different control states. I've achieved this by adding a state, and 3 different content properties to my control.

What I have now is something like that.

  1. User sets CurrentState property to one of, "Default", "CurrentStep" or "Completed".
  2. Control switches to a different visual state via VisualStateManager.
  3. Controls default template sets Visibility property on 3 different ContentPresenters to display single content.

It's all working with no problem. What I am struggling to do is enabling design time support. The only thing I can do is to set ContentProperty attribute to one of the content properties, so that Blend shows this property as a child in it's control tree. However this enables only one content property to be editable in design time.

What more can I do to add design time support to my control?


Solution

  • I would not have created a custom control with multiple contentPresenter.

    To achieve what you are trying to do, most of the time, you create a control with named parts (the default winrt control templates use this "named parts" mechanism). When your custom control state changes, you simply show/hide one or more named parts.

    This way your can provide a default control template, with all the named parts you require, and to customize the control, you override the default template, and define your own parts. The show/hide logic depending on the states will remain the same, but the target control choice is up to the guy writing the template.