1
我想將mousemove事件綁定到對象的實例,然後更新此對象中的一些屬性,我該如何去做這件事?下面是我的XAML:WPF MouseMove在網格上更新對象實例上的位置
<Window.Resources>
<h:AdaptiveObject x:Key="adaptiveObject" />
</Window.Resources>
<Grid Name="Container"
MouseMove="{Binding Source={StaticResource adaptiveObject}, Path=UpdateMouse}"
這裏是當前C#我有,這只是概念,不工作,只是想告訴你什麼,我試圖:
namespace AdaptiveViewport
{
public class AdaptiveObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
public int MouseX { get; set; }
public int MouseY { get; set; }
public UpdateMouse(object sender, MouseEventArgs e)
{
MouseX = e.X;
MouseY = e.Y;
}