QAT, CloneService and derived controls problem

Ribbon for WPF Forum

Posted 10 years ago by Dirk Gaudian - Development Director, Loy & Hutz AG
Version: 4.5.0471
Avatar
I've defined a XAML-Control derived from Group:

<ribbon:Group x:Class="LoyHutz.vFM.RibbonMenu.ObjectGroup"
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"
xmlns:lhrm="clr-namespace:LoyHutz.vFM.RibbonMenu" Label="Objekt" KeyTipAccessText="O" IsCollapsible="False">
<ribbon:Group.Variants>
<ribbon:GroupVariant Priority="10" Size="Small" />
</ribbon:Group.Variants>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="26"/>
<RowDefinition Height="*"/>
<RowDefinition Height="22"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="28"/>
<ColumnDefinition Width="84"/>
</Grid.ColumnDefinitions>
<Image x:Name="Icon" Grid.Row="1" Grid.Column="0" Grid.RowSpan="3" Source="/vFMWPF;component/Resources/111.png" Stretch="Uniform" HorizontalAlignment="Left" Width="24"/>
<ribbon:ButtonGroup Grid.Row="1" Grid.Column="1" VariantSize="Small" HorizontalContentAlignment="Stretch">
<ribbon:Button Name="Search" ImageSourceSmall="/vFMWPF;component/Resources/Search16.png" Width="28" HorizontalContentAlignment="Center" />
<ribbon:Button Name="Insert" ImageSourceSmall="/vFMWPF;component/Resources/New16.png" Width="28" HorizontalContentAlignment="Center" />
<ribbon:Button Name="Select" ImageSourceSmall="/vFMWPF;component/Resources/Select16.png" Width="28" HorizontalContentAlignment="Center" />
</ribbon:ButtonGroup>
<lhrm:MenuAutoCompleteTextBox x:Name="SuperSearch" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" VerticalAlignment="Center" HintText="Supersuche" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
</Grid>
</ribbon:Group>

First Problem: When this Control is added to the QAT, the CloneService will not only deep copy all elements to the QAT, but it will also call ObjectGroup' constructor, which will call InitializeComponent thus creating a second copy of the Control.
We worked around this problem by removing InitializeComponent from the parameterless constructor. We can do that because we need to add instances of ObjectGroup at runtime "by hand" and use an overloaded constructor there. Ugly but it works.

We have no solution for this second problem: lhrm:MenuAutoCompleteTextBox is a control derived from TextBox, that adds quite a few WPF-elements and events in it's constructor. This time the above trick does not work: because it is placed in the XAML code, only the default constructor can and must be called for creation. Now the CloneService will clone the element as such, calling it's constructor and creating all those additional WPF-elements. Additionally it will clone all of the source's elements, (that already where created by the constructor) leaving us with a duplicate set of controls and a ruined functionality.
Is there any way to tell the CloneService just to copy an element but leave out all it's children?

Thank you in advance,
Dirk Gaudian

Comments (2)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Dirk,

You can have your custom TextBox class implement IClonable. When the clone routines encounted an IClonable, they skip the auto-clone functionality and call the IClonable.Clone method instead. Therefore you can use that to customize things however you need.


Actipro Software Support

Posted 10 years ago by Dirk Gaudian - Development Director, Loy & Hutz AG
Avatar
Thanks a Bundle!
You saved my day.
The latest build of this product (v2018.1 build 0675) 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.