我在HubSection中有Grid中的Button,我想在从kg到ibs之后点击Button.Content并从ibs到kg之后更改clik
这是我在XAML中的声明
<Button Content="Button" HorizontalAlignment="Left" Margin="220,-19,0,0" VerticalAlignment="Top"
FontSize="18" Loaded="buttonWeight_Loaded" Click="buttonWeight_Click"/>
这是我的Loaded方法
private void buttonWeight_Loaded(object sender, RoutedEventArgs e)
{
_buttonWeight = (Button)sender;
_buttonWeight.Click += buttonWeight_Click;
}
然后点击方法
private void buttonWeight_Click(object sender, RoutedEventArgs e)
{
if ((_buttonWeight.Content)as String ==this.kg)
{
_buttonWeight.Content = this.ibs;
}
else { _buttonWeight.Content = this.kg; }
}
点击后我总是有ibs为什么?
答案 0 :(得分:2)
您正在注册两次收听Click事件。进入按钮的xaml声明后:
Click="buttonWeight_Click".
并且在Loaded事件中一次:
_buttonWeight.Click += buttonWeight_Click;
摆脱其中任何一个,你的代码就可以了。