如何在Silverlight中将子元素的宽度绑定到父元素的宽度 [英] how to bind width of child element to width of parent element in silverlight

查看:62
本文介绍了如何在Silverlight中将子元素的宽度绑定到父元素的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宽度为1 *的网格。所以在运行时我想到的实际宽度。

在该网格中我有另一个网格,其宽度我想设置为父网格的运行时宽度。我怎样才能做到这一点在XAML通过结合

解决方案
什么有关设置子<网格和GT;'的的 Horizo​​ntalAlignment以拉伸中,这是默认的,实际上?

你也可以随时附加到父< Grid>'s SizeChanged事件 [ ^ ]并从 SizeChangedEventArgs [ ^ ]或读取父 ActualWidth Property



一般绑定方法应如下所示:

 <   grid     width   =  {Binding ElementName = LayoutRoot,Path = ActualWidth}   < span class =code-keyword> /  >  

但在我测试时,它仅适用于VS设计师和不是在运行时间。为什么? - 不知道:(


是的,我之前尝试过,问题是一样的。当我添加一个快速监视时,它显示实际宽度为0.0;(


I have a grid whose width is "1*". So the actual width desided at runtime I think.
Within that grid i have another grid whose width i want to set to the runtime width of parent grid. How Can i do that in xaml through binding.

解决方案

What about setting the child <Grid>''s HorizontalAlignment to Stretch, which is default, in fact?
Also you can always attach to parent <Grid>''s SizeChanged Event[^] and get value from SizeChangedEventArgs[^] or read parent ActualWidth Property.

General Binding approach should look like this:

<grid width="{Binding ElementName=LayoutRoot, Path=ActualWidth}" />

but as I tested it, it worked only in VS designer and not in run-time. Why? -don''t know :(


Yes I have previously tried that and the problem is same.And when I add a quick watch it shows actual width 0.0 ;(


这篇关于如何在Silverlight中将子元素的宽度绑定到父元素的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆