itemscontrol event trigger args equal to null
Posted: 15 Sep 2024, 14:42
I have a collection of elements that I represent using an ItemsControl and each element is a button with which I want to call a certain function from view model by using MVVM pattern if one of the events occurs but the arguments come to the triggered function as null pointer
xaml
ViewModel
xaml
Code: Select all
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Width="30" Height="30" Content="{Binding Index}">
<Button.RenderTransform>
<MultiBinding Converter="{StaticResource PositionConverter}">
<Binding Path="Index"/>
<Binding Path="Theta"/>
<Binding Path="DataContext.Radius" RelativeSource="{RelativeSource AncestorType=UserControl}"/>
<Binding Path="DataContext.CenterX" RelativeSource="{RelativeSource AncestorType=UserControl}"/>
<Binding Path="DataContext.CenterY" RelativeSource="{RelativeSource AncestorType=UserControl}"/>
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}"/>
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</Button.RenderTransform>
<!-- Event Handling for Point Buttons -->
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding DataContext.PointMouseDownCommand, ElementName=RootUserControl}"
PassEventArgsToCommand="True"/>
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseMove">
<i:InvokeCommandAction Command="{Binding DataContext.PointMouseMoveCommand, ElementName=RootUserControl}"
PassEventArgsToCommand="True"/>
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding DataContext.PointMouseUpCommand, ElementName=RootUserControl}"
PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Code: Select all
void CircleViewModel::onPointMouseDown(Noesis::BaseComponent* param) { // here is already null
auto* event_args = Noesis::Boxing::Unbox<Noesis::EventArgs*>(param);
auto* args = (Noesis::MouseButtonEventArgs*)(event_args);
const auto type = param->GetClassType();
isDraggingPoint = true;
lastMousePosition = args->position;
std::cout << "Mouse Down - Point at X: " << lastMousePosition.x << ", Y: " << lastMousePosition.y << std::endl;
}