UE4
Topic Author
Posts: 62
Joined: 29 Dec 2017, 06:32

How to find the control in the ItemsControls in C++?

02 Mar 2018, 05:36

How to find the TouchButton List?
I need to find every TouchButton for Binding event in view code. so I think should get the all TouchButton in the WrapPanel
seems like this but in C++
https://stackoverflow.com/questions/603 ... he-itemtem

 <ItemsControl x:Name="SpellListTemplate" ItemsSource="{Binding SpellList}"  Width="800" Height="150" HorizontalAlignment="Center" VerticalAlignment="Bottom" RenderTransformOrigin="0.5,0.5" Canvas.Left="250" Canvas.Top="500" HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom">
                    <ItemsControl.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform X="0.5" Y="0.5"/>
                        </TransformGroup>
                    </ItemsControl.RenderTransform>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <WrapPanel x:Name="SpellListWrapPanel" Width="800" Height="200">

                                <local:TouchButton Content="SpellButton" FontSize="48" Width="100" Height="100" Foreground="#FFF00202"/>


                            </WrapPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: How to find the control in the ItemsControls in C++?

06 Mar 2018, 14:24

Hi,

First of all I think you want the WrapPanel to be defined in the ItemsControl.ItemsPanel property, because the way you are doing it, would look like this:
ItemsControl
  - StackPanel (default ItemsPanel)
    - ContentPresenter (container for Item 0)
      - WrapPanel (ItemTemplate root)
        - TouchButton
    - ContentPresenter (container for Item 1)
      - WrapPanel (ItemTemplate root)
        - TouchButton
    - ContentPresenter (container for Item 2)
      - WrapPanel (ItemTemplate root)
        - TouchButton
    - ... 
I guess you want this instead:
<ItemsControl...>
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <WrapPanel x:Name="SpellListWrapPanel" Width="800" Height="200"/>
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <local:TouchButton Content="SpellButton" FontSize="48" Width="100" Height="100" Foreground="#FFF00202"/>
    </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl>
Apart from that, as the notes in the accepted answer claim, the FindName used like this will always return null as Container doesn't have registered that name. The search should be done in the template assigned to the container:
var container = _itemsControl.ItemContainerGenerator.ContainerFromItem(dahCurrentItem) as ContentPresenter;
var checkBox = container.ContentTemplate.FindName("MyCheckBox", container) as CheckBox;
And this translates to Noesis C++ like this:
ContentPresenter* container = NsStaticCast<ContentPresenter*>(_itemsControl->GetItemContainerGenerator(dahCurrentItem));
CheckBox* checkBox = NsStaticCast<CheckBox*>(container->GetContentTemplate()->FindName("MyCheckBox", container));

Who is online

Users browsing this forum: No registered users and 1 guest