A avalonia Project,to Drag a control and need to Save the Coordinate,so binding to Left and Top in ViewModel 。but when draged,ViewModel never change when Control is Dragged.
use Avalonia.Xaml.Interactions.Custom.
Front end like this:
<UserControl x:Class="BehaviorsTestApplication.Views.Pages.CustomBehaviorView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:iac="clr-namespace:Avalonia.Xaml.Interactions.Custom;assembly=Avalonia.Xaml.Interactions.Custom"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
</Design.DataContext>
<DockPanel>
<Canvas>
<Image Width="100" Height="100" Canvas.Left="{Binding Left}" IsHitTestVisible="True"
Source="resm:Avalonia.Skia.Assets.NoiseAsset_256X256_PNG.png?assembly=Avalonia.Skia" >
<i:Interaction.Behaviors>
<iac:DragControlBehavior />
</i:Interaction.Behaviors>
</Image>
<TextBlock Text="{Binding Left }" Canvas.Top="200" />
</Canvas>
</DockPanel>
</UserControl>
and ViewModel
private double _left=60;
public double Left
{
get=>_left;
set=>this.RaiseAndSetIfChanged(ref _left,value);
}
When Drag the Control,is there any way to get Canvas Coordinate? than you