[英]Update UI by code in WPF
I'm trying to update some user control in wpf by code, with no luck. 我正在尝试通过代码更新wpf中的某些用户控件,但是没有运气。
That's the xaml: 那就是xaml:
<UserControl x:Class="SimuladorNocs.UI.Diagram.PropertiesWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:PropertyGrid="clr-namespace:Deepforest.WPF.Controls"
>
<DockPanel>
<StackPanel x:Name="stackPanel" Width="300" Height="600" HorizontalAlignment="Center">
<PropertyGrid:PropertyGridControl Height="300" x:Name="MyPropertyGrid" />
</StackPanel>
</DockPanel>
and that's the c# code: 那就是C#代码:
public void SetInstance(object obj){
MyPropertyGrid = new PropertyGridControl { Instance = obj, Height = 300 };
stackPanel.Children.Clear();
stackPanel.Children.Add(MyPropertyGrid); }
In the end, the property appers to be changing, but I was unable to see the changes in the UI. 最后,该属性似乎正在更改,但是我无法在UI中看到更改。 I also tried to create a new object instead of using the existing MyPropertyGrid, did not work, also tried not clearing the stackpanel without success...
我还尝试创建一个新对象而不是使用现有的MyPropertyGrid,但没有成功,还尝试了不清除堆栈面板而没有成功...
What am I missing? 我想念什么?
Thanks 谢谢
I don't have the specified propertygrid control but it seems that the UI doesn't get updated. 我没有指定的propertygrid控件,但是UI似乎没有更新。 did you try "UpdateLayout()" on that control and on the stack panel itself ?
您是否在该控件以及堆栈面板本身上尝试了“ UpdateLayout()”?
stackPanel.InvalidateVisual();
请在最后一行添加。
Swapped out the PropertyGridControl
for a Label
and it worked fine. 将
PropertyGridControl
换成Label
,它工作正常。 I suggest you do the same. 我建议你这样做。 If it works, it's more a question of what the
PropertyGridControl
is doing wrong... 如果可行,那就更多是一个关于
PropertyGridControl
做错了什么的问题...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.