我在画布上有一堆线条.我想迭代线条并将它们的笔触颜色变为黑色.
foreach循环中的代码行将无法编译.
foreach (FrameworkElement Framework_Element in My_Canvas.Children)
{
//the following line of code won't compile.
(Line)Framework_Element.Stroke = new SolidColorBrush(Colors.Black);
}
Run Code Online (Sandbox Code Playgroud)
你缺少一对括号.
foreach (FrameworkElement Framework_Element in My_Canvas.Children)
{
// tries to find .Stroke on the FrameworkElement class
// (Line)Framework_Element.Stroke
// correct way
((Line)Framework_Element).Stroke = new SolidColorBrush(Colors.Black);
// or
var currentLine = (Line)Framework_Element;
currentLine.Stroke = new SolidColorBrush(Colors.Black);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7175 次 |
| 最近记录: |