【发布时间】:2015-02-13 18:39:33
【问题描述】:
我的 XAML 代码中有这个按钮-
<Button x:Name="button"
Content="{Binding Name}"
Click="Start"
HorizontalAlignment="Left"
Margin="123,45,0,0"
VerticalAlignment="Top"/>
我还有另一个 C# 代码-
namespace MyGame
{
public sealed partial class MainPage : Page
{
public string Name()
{
get{ return "Hello" };
}
private void ButtonNo3(object sender, RoutedEventArgs e)
{
Button obj = (Button)sender;
var selectedButton = obj.Content.ToString();
//This is where I get this error-An exception of type 'System.NullReferenceException' occurred in MyGame.exe but was not handled in user code
}
}
}
我的问题是如何在我的xaml 代码中获取Button 的Content 以存储来自C# 代码函数的值?
【问题讨论】:
标签: c# xaml visual-studio-2012 visual-studio-2013