C# Windows phone 8.1访问按钮

C# Windows phone 8.1访问按钮,c#,xaml,windows-phone-8.1,windows-phone,C#,Xaml,Windows Phone 8.1,Windows Phone,我正在尝试访问我的xaml页面中的按钮。我会让他们的前景变成红色。但我无法访问它们 for (int i = 1; i <= 10; i++) { Button button = this.FindName("Button_" + i); button.IsEnabled = false; button.Foreground = new SolidColorBrush(Colors.Red); } for(int

我正在尝试访问我的xaml页面中的按钮。我会让他们的前景变成红色。但我无法访问它们

for (int i = 1; i <= 10; i++)
{
      Button button = this.FindName("Button_" + i);
      button.IsEnabled = false;
      button.Foreground = new SolidColorBrush(Colors.Red);                    
}

for(int i=1;i您需要强制转换
FindName的返回值

  Button button = (Button)this.FindName("Button_" + i);

如果这解决了你的问题,请勾选箭头接受答案