Need help with RibbonGallery

Ribbon for WPF Forum

Posted 11 years ago by LaurentB - Intersystems
Avatar
Helo,

I want to create a RibbonGallery that contains Labels. I can display it fine, but if I open the list and then close, the labels desappear. Where are they ?

This is the XAML of my Window :

<ribbon:RibbonWindow x:Class="WpfApplication4.RibbonWindow1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared" 
    xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon" 
    ApplicationName="RibbonWindow1" Width="620" Height="420">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid/>
        <ribbon:Ribbon x:Name="ribbon" Grid.Row="0">
            <ribbon:Ribbon.Tabs>
                <ribbon:Tab Label="Home" KeyTipAccessText="H">
                    <ribbon:Group Label="New Group">
                        <ribbon:RibbonGallery IsSelectionHighlightVisible="False">
                            <ribbon:RibbonGallery.ItemsSource>
                                <x:Array Type="{x:Type Label}">
                                    <Label Content="sss1"/>
                                    <Label Content="sss2"/>
                                    <Label Content="sss3"/>
                                    <Label Content="sss4"/>
                                    <Label Content="sss5"/>
                                    <Label Content="sss6"/>
                                    <Label Content="sss7"/>
                                    <Label Content="sss8"/>
                                    <Label Content="sss9"/>
                                    <Label Content="sss10"/>
                                </x:Array>
                            </ribbon:RibbonGallery.ItemsSource>
                            <ribbon:RibbonGallery.ItemTemplate>
                                <DataTemplate>
                                    <Label Content="{Binding BindsDirectlyToSource=True}" />
                                </DataTemplate>
                            </ribbon:RibbonGallery.ItemTemplate>
                            <ribbon:RibbonGallery.PopupContent>
                                <StackPanel>
                                    <ribbon:PopupGallery InitialColumnCount="4" IsSelectionHighlightVisible="False"
                                        ItemTemplate="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ribbon:RibbonGallery}}, Path=ItemTemplate, Mode=Default}" 
                                        ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ribbon:RibbonGallery}}, Path=ItemsSource, Mode=Default}"
                                        />
                                </StackPanel>
                            </ribbon:RibbonGallery.PopupContent>
                        </ribbon:RibbonGallery>
                    </ribbon:Group>
                </ribbon:Tab>
            </ribbon:Ribbon.Tabs>
        </ribbon:Ribbon>
    </Grid>
</ribbon:RibbonWindow>
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ActiproSoftware.Windows.Controls.Ribbon.Controls;

namespace WpfApplication4
{

/// <summary>
/// Interaction logic for RibbonWindow1.xaml.
/// </summary>
public partial class RibbonWindow1 : ActiproSoftware.Windows.Controls.Ribbon.RibbonWindow
{

public RibbonWindow1()
{
InitializeComponent();
}

}
}

Many thanks

Comments (2)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The problem here is that you are trying to use a Visual in two places: in-ribbon gallery and the popup gallery. When the popup gallery shows, it removes the Visuals from the in-ribbon gallery and shows them in the popup. That is just how WPF works since Visuals can only be used in one spot at a time.

Instead of using Visuals as an ItemsSource, you need to bind an array of objects or strings, etc. Since those sorts of data items aren't Visuals, they can freely be used between both gallery instances without any issues like this.


Actipro Software Support

Posted 11 years ago by LaurentB - Intersystems
Avatar
OK, I understand

Many thanks
The latest build of this product (v2019.1 build 0683) 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.