如何强制刷新绑定 [英] How to force a refresh of binding
问题描述
亲爱的,
我在列表框中有一个组件,其高度绑定到另一个控件高度,该高度托管在设置为自动的网格行中
I have a component in a listbox where its Height is bind to an other control Height which is hosted in a grid row set to Auto
myControl.Height="{Binding ElementName=_mainChart,Path=ActualHeight}"
在我的viewmodel中,我需要通过代码更改名为_mainChart的控件的高度值
In my viewmodel, I need to change the Height value of my control named _mainChart through code
最初_mainChart.ActualHeigth = 200
Initially _mainChart.ActualHeigth=200
然后当我把它改成代码时,我做的就是 下面:
Then when I change it to code, I do is as below :
_mainchart.Width = 200;
_mainchart.Height = 400;
_mainchart.UpdateLayout();
然后我对这个新大小做一些操作然后重新设置它:
Then I do some operation on this new size and then reset it back :
_mainchart.Width = double.Nan;
_mainchart.Height = double.Nan;
_mainchart.UpdateLayout();
在此阶段,_ mainChart.Height已更改回来,但myControl.Height不再正确绑定到_mainChart的ActualHeight
At this stage, _mainChart.Height has change back but the myControl.Height is not anymore bind correctly to ActualHeight of _mainChart
如何强制刷新 myControl.Height =" {Binding ElementName = _mainChart,Path = ActualHeight }",它是为了再次获得正确的价值?
How can I force a refresh of myControl.Height="{Binding ElementName=_mainChart,Path=ActualHeight}", it order to gets correct value again ?
寻求帮助
推荐答案
如果你设置了一个属性代码绑定时你会破坏绑定。
If you set a property in code while it is bound you will destroy the binding.
这与你刚才提出的问题几乎相同。 你应该永远不需要UpdateLayout,所以你的XAML会阻止你。 (提示显示它真的可以帮助我们)。
This is pretty much the same question you asked a while ago. You should never need UpdateLayout so it something about your XAML that is stopping you. (Hint showing it would really help us help you).
这篇关于如何强制刷新绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!