wpf c# 检查网格中是否存在对象
大家好 我有一个问题
,是否有一个由 xaml 构建的网格,并且在该网格中,有许多由 C# 语法创建的对象。
如何访问该对象或知道该网格中有对象。
例如。在我的网格中,首先是空的,但是当我单击网格站点外的按钮后,会创建一些对象,例如文本块和列表框。不,我还有另一个按钮来检查并列出该网格中的对象。这是 xaml 代码:
<Grid x:Name="LayoutRoot">
<TabControl Margin="0,0,0,141">
<TabItem Header="TabItem">
<Grid Background="#FFE5E5E5"/>
</TabItem>
</TabControl>
<Button Content="Create Object" HorizontalAlignment="Left" Margin="87,0,0,54.04" VerticalAlignment="Bottom" Width="105"/>
<Button Content="check object" HorizontalAlignment="Right" Margin="0,0,237,54.04" VerticalAlignment="Bottom" Width="75"/>
<ListBox HorizontalAlignment="Right" Height="82" Margin="0,0,100,21" VerticalAlignment="Bottom" Width="101"/>
</Grid>
请帮助我
Hi every one
i have a question
if there is a grid built by xaml, and in that grid there are many object created prgrammically by c#.
how to accsess that objects or know there are objects in that grid.
for example. in my grid first is empty, but after i click the button out site of the grid, that create some object like textblock and listbox. nah I have one other button to check and listing what object in that grid. this the xaml code :
<Grid x:Name="LayoutRoot">
<TabControl Margin="0,0,0,141">
<TabItem Header="TabItem">
<Grid Background="#FFE5E5E5"/>
</TabItem>
</TabControl>
<Button Content="Create Object" HorizontalAlignment="Left" Margin="87,0,0,54.04" VerticalAlignment="Bottom" Width="105"/>
<Button Content="check object" HorizontalAlignment="Right" Margin="0,0,237,54.04" VerticalAlignment="Bottom" Width="75"/>
<ListBox HorizontalAlignment="Right" Height="82" Margin="0,0,100,21" VerticalAlignment="Bottom" Width="101"/>
</Grid>
please help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能不是最容易做的事情,但它已经写好了,所以您需要了解它的工作原理并使用它:Linq to Visual Tree
http://www.scottlogic.co。 uk/blog/colin/2010/03/linq-to-visual-tree/
它对我正在从事的一个项目有帮助。
This may not be the easiest thing to do, but it's been written already so it's up to you to understand how it works and use it: Linq to Visual Tree
http://www.scottlogic.co.uk/blog/colin/2010/03/linq-to-visual-tree/
It helped me in a project I was working on.