简体   繁体   English

从文件内迭代XAML元素

[英]Iterating XAML elements from within a file

I have an application that loads a XAML file, and shows it in a ContentControl . 我有一个加载XAML文件并将其显示在ContentControl的应用程序。 What I also want to implement is a way to go over the XAML code that was loaded to the control and populate a listbox with the names of the Canvases I find. 我还想实现的一种方法是遍历已加载到控件的XAML代码,并使用我找到的Canvas的名称填充列表框。

The main task of this tiny application is to enable the user to change colors of specific canvases and their elements. 这个微型应用程序的主要任务是使用户能够更改特定画布及其元素的颜色。 Meaning that I have, for example 10 canvases, each containing some <Path> elements. 这意味着我有10个画布,每个画布包含一些<Path>元素。 I want to give the user a list of the canvases that were found in the XAML code, and for each canvas the user will be able to change its fill color (for example), if the user changes the fill color of a specific canvas, the child elements of that canvas will change their "Fill" attribute to the selected color as well. 我想给用户一个在XAML代码中找到的画布的列表,并且对于每个画布,用户都可以更改其填充颜色(例如),如果用户更改了特定画布的填充颜色,该画布的子元素也会将其“填充”属性也更改为所选颜色。

I didn't find a way to iterate through the Canvases or the Path elements, so if anyone have a way to do this I would be glad to hear. 我没有找到遍历Canvases或Path元素的方法,因此,如果有人有办法做到这一点,我将很高兴听到。

Thanks! 谢谢!

You seem to need to traverse the logical children tree of a given control. 您似乎需要遍历给定控件的逻辑子树。 For this, you need to use LogicalChildren property recursively. 为此,您需要递归使用LogicalChildren属性。

You can find more information on the element trees in WPF here . 你可以找到在WPF的元素树的详细信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM