简体   繁体   中英

Update UI by code in WPF

I'm trying to update some user control in wpf by code, with no luck.

That's the 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:

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. 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...

What am I missing?

Thanks

I don't have the specified propertygrid control but it seems that the UI doesn't get updated. did you try "UpdateLayout()" on that control and on the stack panel itself ?

stackPanel.InvalidateVisual();

请在最后一行添加。

Swapped out the PropertyGridControl for a Label and it worked fine. I suggest you do the same. If it works, it's more a question of what the PropertyGridControl is doing wrong...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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