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

Behavior with Event inside Style

05 Jun 2019, 18:16

Hi
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">
          <TabControl.Resources>     
        
              <Style TargetType="{x:Type TabItem}">
                <Setter Property="Template">
                  <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabItem}">
                      <Grid Height="25">
                     		<i:Interaction.Behaviors>
                         		 <docking:LayoutDragElementBehavior OnDrag="OnTabItemDrag"/>
                      		  </i:Interaction.Behaviors>
                        
                        <Border Name="Border" Background="Transparent"  BorderThickness="0" CornerRadius="0"  Margin="0"  BorderBrush="#303030">
                          <TextBlock />
                        </Border>
                      </Grid>
                    </ControlTemplate>
                  </Setter.Value>
                </Setter>
              </Style>
        
          </TabControl.Resources>
        </TabControl>
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Behavior with Event inside Style

06 Jun 2019, 17:46

Hi,

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)
{
    ParentClass::CloneCommonCore(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();
        thisActions->Add(action);
    }
}
I think it is better to use the default constructor in the CreateInstanceCore method, and override the CloneCommonCore for extending the clone process.
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: Behavior with Event inside Style

07 Jun 2019, 08:07

Thanks
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

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: Bing [Bot], Google [Bot] and 77 guests