Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Behavior with Event inside Style

05 Jun 2019, 18:16

I implemented Behavior in which there is an Event. If I attach this Behavior to the element that is inside Style.ControlTemplate ..., then the event is not called. When invoking Event, the list of delegates is empty. As I understand it, when using inside Styles, you need to clone the Behavior created in Style.

How to act in this case?

In the method of
         Noesis::Ptr<Noesis::Freezable> LayoutDragElementBehavior::CreateInstanceCore() const
		return *new LayoutDragElementBehavior(mDragEvent);
I create a Behavior instance with an existing event. It works.
        <TabControl x:Name="tab" Visibility="Collapsed" TabStripPlacement="Bottom" BorderThickness="0.5" BorderBrush="#303030" SelectionChanged="OnTabSelectionChanged">
              <Style TargetType="{x:Type TabItem}">
                <Setter Property="Template">
                    <ControlTemplate TargetType="{x:Type TabItem}">
                      <Grid Height="25">
                         		 <docking:LayoutDragElementBehavior OnDrag="OnTabItemDrag"/>
                        <Border Name="Border" Background="Transparent"  BorderThickness="0" CornerRadius="0"  Margin="0"  BorderBrush="#303030">
                          <TextBlock />
User avatar
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Behavior with Event inside Style

06 Jun 2019, 17:46


The Freezable class exposes the virtual method CloneCommonCore() where any inheriting class can perform their own clone code.

For example, the TriggerBase class in the Interactivity package (available in the Native SDK under Src/Packages/App/Interactivity/Src folder) uses that method to clone its collection of actions:
void NoesisApp::TriggerBase::CloneCommonCore(const Freezable* source)

    TriggerActionCollection* thisActions = GetActions();

    TriggerBase* trigger = (TriggerBase*)source;
    TriggerActionCollection* actions = trigger->GetActions();
    int numActions = actions->Count();
    for (int i = 0; i < numActions; ++i)
        Ptr<TriggerAction> action = actions->Get(i)->Clone();
I think it is better to use the default constructor in the CreateInstanceCore method, and override the CloneCommonCore for extending the clone process.
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: Behavior with Event inside Style

07 Jun 2019, 08:07

User avatar
Site Admin
Posts: 3914
Joined: 20 Jan 2012, 17:18

Re: Behavior with Event inside Style

10 Jun 2019, 12:56

Marking as solved. Thanks for your feedback.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], kaijin and 0 guests