English 中文(简体)
在WPF中,给定UIElementCollection,请查找所有具有StyleA的元素,并将它们更改为StyleB。
原标题:Given UIElementCollection, find all elements that have StyleA, and change them to StyleB in WPF

我走了门。 Children UIElementCollection, 我想找到它中所有有风格的异构体,并把它们打成型B。

如果可能的话,我想使用LINQ,这样我就可以避免一个讨厌的嵌套循环。

像这样的伪代码:

var Recs = from r in MyGrid.Children
                  where r.Style == StyleA && r.GetType() == typeof(Rectangle)
                  select r as Rectangle;

然后:

foreach(Rectangle r in Recs)
   r.Style = StyleB;

能否有一个LINQ专家帮助我提高我的LINQ技能?

最佳回答

你们的法典几乎是正确的,但独立实体没有像样的财产。 能够根据儿童的类型过滤网格儿童:

var recs = from r in MyGrid.Children.OfType<Rectangle>()
           where r.Style == StyleA
           select r;

foreach(Rectangle r in recs)
   r.Style = StyleB;
问题回答

暂无回答




相关问题
Creating a Style in code behind

Does anyone know how to create a wpf Style in code behind, I can t find anything on the web or MSDN docs. I have tried this but it is not working: Style s = new Style(typeof(TextBlock)); s....

WPF Custom Themes

I have a simple question which is giving me some difficulty. I have downloaded a custom them for WPF of the net. Now i want to apply this theme to my App instead of the default one. How do i do that,...

Is it sometimes bad to use <BR />?

Is it sometimes bad to use <BR/> tags? I ask because some of the first advice my development team gave me was this: Don t use <BR/> ; instead, use styles. But why? Are there negative ...

WPF - How to apply effect to a cropped image?

I have an Image being clipped like so: <Image Width="45" Grid.Column="0" Source="{Binding Photo}"> <Image.Clip> <RectangleGeometry Rect="0,0,45,55" RadiusX="8" RadiusY="8" /...

WPF ListView : Header styling

I want to have a ListView with columns and a particular style: The background for ALL column headers should be transparent except when the mouse is over in one of them. When this happends, the ...

热门标签