i'M真正新地为C#(1-2天...)。我仍然没有如何访问网格并测试详细信息中的按钮&列设置为true的属性" IseNabled"。我想测试蓝色按钮是否启用蓝色按钮。
我不知道如何编写测试,访问 @ [row] [col]的按钮(或[i] [j]在这种情况下...)和他的属性" IseNabled"。这是一个8*8网格,带有按钮。非常感谢您的帮助。
public bool isButtonAvaible(Button button)
{
row = (int)button.GetValue(Grid.RowProperty);
col = (int)button.GetValue(Grid.ColumnProperty);
foreach (Button b in gridBoard.Children) //not sure if correct/needed
{
for (int i = row - 1; i <= row + 1; i++)
{
for(int j = col - 1; j <= col +1; j++)
{
if(gridBoard.Children ??? (Button.IsEnabledProperty ==true)
{
return true;
}
}
}
}
return false;
}
蓝色按钮上的测试概念
如果要运行测试以查看启用按钮是否已启用,就像您已经格式化了功能一样,它就像
一样容易public bool isButtonAvailable(Button btn)
{
return btn.IsEnabled;
}
IsEnabled
是一个布尔值属性,因此,如果您要将按钮作为参数传递给此功能,则只想返回您是否启用的按钮是否启用的true/fals。您尝试过的其他一切 - 做太多。
private static Button GetChildren(Grid grid, int row, int column)
{
foreach (Button child in grid.Children)
{
if (Grid.GetRow(child) == row
&&
Grid.GetColumn(child) == column)
{
return child;
}
}
return null;
}
,但它也可能更通用:public UIElement GetChildren(etc
...){}