C# 单击vs Hold,Hold导致语法错误
这是我的XAML:C# 单击vs Hold,Hold导致语法错误,c#,silverlight,xaml,windows-phone,C#,Silverlight,Xaml,Windows Phone,这是我的XAML: <Button x:Name = "Helloworld" Content = "Hello world" Grid.Column = "0" Grid.Row = "0" Click="playEvent"
<Button x:Name = "Helloworld"
Content = "Hello world"
Grid.Column = "0"
Grid.Row = "0"
Click="playEvent"
Hold="setEvent"
Tag="/Sounds/helloworld.mp3"
/>
<Button x:Name = "Helloworld_ring"
Grid.Column = "1"
Grid.Row = "0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="setEvent"
Tag="/Sounds/helloworld.mp3">
<Image Source="/Images/note.png" Stretch="Fill" Height="30" Width="30" />
</Button>
据我所知,这是很难描述的。但我注意到的问题是,在调试过程中,setSrcButton变量没有获得e.OriginalSource的值,但这只在我在Helloworld上使用Hold事件时发生。当我在Helloworld_ring上使用Click事件时,一切正常
感谢所有的帮助。谢谢:)也许e.OriginalSource不是您的按钮 在这种情况下,发送者应该是您的按钮,因此请尝试使用该按钮
setSrcButton = sender as Button;
虽然我希望有人能解释为什么会这样,但我非常感谢你的回答。现在可以了。非常感谢。
An unhandled exception of type 'System.NullReferenceException' occurred in MyApp.dll
setSrcButton = sender as Button;