hitch
Topic Author
Posts: 5
Joined: 20 Oct 2019, 10:34

Changing Grid.GetRowDefinitions Grid.GetColumnDefinitions via attached property not working

04 Nov 2019, 21:58

Hi There

I am trying to implement an example Inventory Screen in Unreal Engine 4.22.2 with Noesis. A part of this inventory screen consists of a Grid which shows the content of a backpack or vest or the like. The grid needs to be setup dynamically (Number of columns/rows) depending on the size of backpack/vest but the grid itself will be evenly distributed.

By the way: We don't use your "unreal to noesis" type wrappers since our view models are pure C++ with Noesis, without any UE code or uproperties/ufunctions, however we use the Noesis UEPlugin of course.

The xaml around the grid looks like:
...
  <ItemsControl Grid.Row="2" ItemsSource="{Binding SubObjectSockets}">
    <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate>
        <Grid doiUi:WpfGridExtensions.ColumnCount="5" doiUi:WpfGridExtensions.RowCount="2" />
        <!-- <Grid doiUi:WpfGridExtensions.ColumnCount="{Binding XSize}" doiUi:WpfGridExtensions.RowCount="{Binding YSize}" /> -->
      </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
      <Style>
        <Setter Property="Grid.Row" Value="{Binding YPos}" />
        <Setter Property="Grid.Column" Value="{Binding XPos}" />
      </Style>
    </ItemsControl.ItemContainerStyle>
    <ItemsControl.ItemTemplate>
      <DataTemplate>
        <Grid>
          <Canvas Height="50" Width="50"></Canvas>
          <Image Margin="3,3,3,3" Source="{Binding ObjectImage}" Stretch="Uniform" />
        </Grid>
      </DataTemplate>
    </ItemsControl.ItemTemplate>
  </ItemsControl>
...
So I am using the attached properties WpfGridExtensions.ColumnCount and WpfGridExtensions.RowCount which in turn use their ProperyChanged callback to setup the Grid's Column/Row Definitions:
...
  static void ColumnCountPropertyChangedCallback(Noesis::DependencyObject* obj, const Noesis::DependencyPropertyChangedEventArgs& args)
  {
    Noesis::Grid* grid = Noesis::DynamicCast<Noesis::Grid*>(obj);
    if(!grid) return;

    int columnCount = *static_cast<const int*>(args.newValue);
    if(columnCount < 0) return;

    Noesis::ColumnDefinitionCollection* columnDefinitions = grid->GetColumnDefinitions();
    columnDefinitions->Clear();

    for(int i = 0; i < columnCount; ++i) {
      auto columnDefinition = new Noesis::ColumnDefinition();

      columnDefinition->SetWidth(Noesis::GridLength(1.0f, Noesis::GridUnitType_Star));

      columnDefinitions->Add(columnDefinition);
    }
  }
...
The RowCountPropertyChangedCallback does the same with rowDefinitions. What I expect is that the grid would be setup similar to the following XAML:
...
<ItemsPanelTemplate>
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="1*" />
      <!-- a dynamic number of such ColumnDefinitions... -->
    <Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="1*" />
      <!-- a dynamic number of such RowDefinitions... -->
    </Grid.RowDefinitions>
  </Grid>
</ItemsPanelTemplate>
...
The attached properties are working, the C++ PropertyChanged callbacks are called and seem to execute correctly, so the XXXDefinintions->Add(...) return values >= 0, but there is no visible effect, the Grid stays in a "collapsed" state in C++/UE4, while it is perfectly working in C#/WPF with the "corresponding C# code" and inside the visual studio designer with a designtime viewmodel.

There are no errors Reported in the UE Noesis Logoutput when I open the view, the LogLevel is set to "Bindings".

Am I missing something?

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1683
Joined: 22 Dec 2011, 19:20

Re: Changing Grid.GetRowDefinitions Grid.GetColumnDefinitions via attached property not working

08 Nov 2019, 13:37

I found what is going on, the problem is that setting Grid.Column and Grid.Row properties is not invalidating Grid's layout.
Could you please report this issue in our bugtracker?
 
User avatar
sfernandez
Site Admin
Posts: 1683
Joined: 22 Dec 2011, 19:20

Re: Changing Grid.GetRowDefinitions Grid.GetColumnDefinitions via attached property not working

08 Nov 2019, 16:53

Created this ticket to track it: #1582
 
hitch
Topic Author
Posts: 5
Joined: 20 Oct 2019, 10:34

Re: Changing Grid.GetRowDefinitions Grid.GetColumnDefinitions via attached property not working

09 Nov 2019, 18:22

Thanks a lot! We will try to trigger the invalidation in some other way or find a different layout as a workaround until we get the bugfix.
 
User avatar
jsantos
Site Admin
Posts: 2607
Joined: 20 Jan 2012, 17:18
Contact:

Re: Changing Grid.GetRowDefinitions Grid.GetColumnDefinitions via attached property not working

13 Nov 2019, 11:43

It was fixed and will be available in the next minor version. Thanks for your patience!
 
hitch
Topic Author
Posts: 5
Joined: 20 Oct 2019, 10:34

Re: Changing Grid.GetRowDefinitions Grid.GetColumnDefinitions via attached property not working

14 Nov 2019, 10:06

Ok, looks like I got another one:

If you look at the code I posted before you see that I am trying to set the attached properties "Grid.Row" and "Grid.Column" via setters in the ItemContainerStyle:
    <ItemsControl.ItemContainerStyle>
      <Style>
        <Setter Property="Grid.Row" Value="{Binding YPos}" />
        <Setter Property="Grid.Column" Value="{Binding XPos}" />
      </Style>
    </ItemsControl.ItemContainerStyle>
Again this does not seem to work. The grid itself is now configured correctly (I added a few lines for invalidation due to the previous problem), but all children are now sitting in the upper left corner of the gird, as if those setters had no effect. As WPF/C# Windows Application and inside VS2019 XAML Designer with a design time viewmodel everything works just fine...

Do we have a similar issue here?

If yes, is there some trick that I could use to make it work?
 
hitch
Topic Author
Posts: 5
Joined: 20 Oct 2019, 10:34

Re: Changing Grid.GetRowDefinitions Grid.GetColumnDefinitions via attached property not working

14 Nov 2019, 12:07

What I tried now: I used the VisualTreeHelper to find such Inventory Grids and triggered again a layout invalidation - of course after all child elements have been added/emplaced. After that the grid and all content are shown as expected, so it really seems to be a similar issue here.
 
User avatar
sfernandez
Site Admin
Posts: 1683
Joined: 22 Dec 2011, 19:20

Re: Changing Grid.GetRowDefinitions Grid.GetColumnDefinitions via attached property not working

14 Nov 2019, 12:11

I think it is related, because the problem was that those setters were applied to the children inside the measure of the Grid itself, ignoring those changes at that moment.
Invalidating the Grid again in the next layout pass would make the Grid re-evaluate children row/column values and it will work fine then.
 
hitch
Topic Author
Posts: 5
Joined: 20 Oct 2019, 10:34

Re: Changing Grid.GetRowDefinitions Grid.GetColumnDefinitions via attached property not working

14 Nov 2019, 12:38

So do you consider this to be a bug? Or does the previous fix also fix this issue?
 
User avatar
sfernandez
Site Admin
Posts: 1683
Joined: 22 Dec 2011, 19:20

Re: Changing Grid.GetRowDefinitions Grid.GetColumnDefinitions via attached property not working

14 Nov 2019, 12:54

The previous fix will solve this too.

Who is online

Users browsing this forum: Bing [Bot] and 1 guest