- realesmedia
- Posts: 85
- Joined:
Subscribe to the Behavior event from code
Hi
I need to connect to the <TranslateZoomRotateBehavior Dragging = "..." /> event from code
like this the event is not triggered:
in VisualTree UserControl is inside <ItemsControl ItemsSource="{Binding InConnectors}"/>
I need to connect to the <TranslateZoomRotateBehavior Dragging = "..." /> event from code
Code: Select all
<DataTemplate>
<Border x:Name="PART_NodeRoot" Width="100" Height="Auto" MinHeight="50" Background="#f0202025" CornerRadius="5" Padding="0,0,0,10"
BorderThickness="0.5" BorderBrush="#050505" Cursor="ScrollAll"
PreviewMouseLeftButtonDown="OnNodeMouseDown">
<i:Interaction.Behaviors>
<TranslateZoomRotateBehavior x:Name="PART_Behavior" SupportedGestures="Translate"
Dragging="OnNodeDragging"
X="{Binding Position.X, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Y="{Binding Position.Y, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Scale="1.0"/>
</i:Interaction.Behaviors>
<Grid>
<ItemsControl ItemsSource="{Binding InConnectors}" HorizontalAlignment="Left" Margin="7,30,0,0">
<ItemsControl ItemsSource="{Binding OutConnectors}" HorizontalAlignment="Right" Margin="0,30,7,0"/>
</Grid>
</Border>
</DataTemplate>
Code: Select all
UserControl() {
Loaded() += [this] (BaseComponent*, const RoutedEventArgs& e) {
if (auto border = Helper::GetParentRecursive<Border>(this)) {
if(auto behavior = border->FindName<TranslateZoomRotateBehavior>("PART_Behavior")) {
behavior->Dragging() += [...] (....) {
printf("Not call");
};
}
}
};
}
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Subscribe to the Behavior event from code
Hi, there is a known issue about some objects not being correctly registered in the NameScope when they are part of a template: https://www.noesisengine.com/bugs/view.php?id=1476
While we fix this issue you can change your code to get the behaviors directly from the BehaviorCollection, something like this:
While we fix this issue you can change your code to get the behaviors directly from the BehaviorCollection, something like this:
Code: Select all
UserControl() {
Loaded() += [this] (BaseComponent*, const RoutedEventArgs& e) {
if (auto border = Helper::GetParentRecursive<Border>(this)) {
auto behaviors = Interaction::GetBehaviors(border);
auto behavior = DynamicCast<TranslateZoomRotateBehavior*>(behaviors->Get(0));
behavior->Dragging() += [...] (....) {
printf("Dragging!");
};
}
}
};
}
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 17 guests