caiokf
caiokf

Reputation: 344

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

Upvotes: 0

Views: 5806

Answers (3)

Kent Boogaart
Kent Boogaart

Reputation: 178660

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

Upvotes: 0

Akash Kava
Akash Kava

Reputation: 39916

stackPanel.InvalidateVisual();

Please add this at the last line.

Upvotes: 2

ExistMe
ExistMe

Reputation: 529

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 ?

Upvotes: 1

Related Questions