Using an Resource Dictionary item in a Group

Ribbon for WPF Forum

Posted 14 years ago by Arthur Damen
Version: 10.1.0523
Avatar
Hi,
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"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
    Title="MainWindow" Height="350" Width="525">
  <Window.Resources>
    
    <ribbon:StackPanel x:Key="PP" ItemVariantBehavior="MediumThenSmallWhenSmall">
      <ribbon:PopupButton Label="Popup">
      <ribbon:Menu>
        <ribbon:Button Label="Item 1"></ribbon:Button>
        <ribbon:Button Label="Item 2"></ribbon:Button>
      </ribbon:Menu>
      </ribbon:PopupButton>
      <ribbon:Button Label="aaa" />
      <ribbon:Button Label="bbb" />
    </ribbon:StackPanel>
    
  </Window.Resources>
  <Grid>
    <ribbon:Ribbon>
      <ribbon:Tab>
        <ribbon:Group>
          <ContentControl Content="{StaticResource PP}"></ContentControl>
          <ribbon:Separator></ribbon:Separator>
          <ribbon:Button Label="new btn"></ribbon:Button>
          
        </ribbon:Group>
      </ribbon:Tab>
    </ribbon:Ribbon>

  </Grid>
</Window>
[Modified at 09/03/2010 02:31 AM]

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
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.3) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.