Subscribe to the Behavior event from code
Posted: 18 Jun 2019, 11:06
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");
};
}
}
};
}