Using an Resource Dictionary item in a Group

Ribbon for WPF Forum

Posted 14 years ago by Arthur Damen
Version: 10.1.0523
I want to create a resource dictionary (stackpanel) item for an item that must be shown in different tabs in my ribbonbar.

In the following example I used a contentcontrol as container.
Is this the right way or is there a better ribbon container to use??

2nd problem i encounter is that when I add another contentcontrol with the same staticresource i get the logicalchild is already connected to a different element error. So I am not able to load 2 resources...

<Window x:Class="MainWindow"
    Title="MainWindow" Height="350" Width="525">
    <ribbon:StackPanel x:Key="PP" ItemVariantBehavior="MediumThenSmallWhenSmall">
      <ribbon:PopupButton Label="Popup">
        <ribbon:Button Label="Item 1"></ribbon:Button>
        <ribbon:Button Label="Item 2"></ribbon:Button>
      <ribbon:Button Label="aaa" />
      <ribbon:Button Label="bbb" />
          <ContentControl Content="{StaticResource PP}"></ContentControl>
          <ribbon:Button Label="new btn"></ribbon:Button>

[Modified at 09/03/2010 02:31 AM]

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Arthur,

Yes if you define a UIElement as a resource, it is static and can't be used more than one place. You'd have to define a DataTemplate as a resource instead and put your UIElement in that. That way it's can be created multiple times. But even with that, I'm not sure offhand if the item variant changes will work in that case since you are embedding the StackPanel in the ContentControl.

If that doesn't work, another thing you can do is make a dedicated StackPanel-based class just like you do for Windows and UserControls where you have the XAML for it, and you reference its class via x:Class and have code-behind that calls InitializeComponent. That way you just insert a local:MyCustomStackPanel in multiple places in the UI and everything should work properly.

Actipro Software Support

The latest build of this product (v24.1.2) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.