How to find the control in the ItemsControls in C++?
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
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
Code: Select all
<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>
-
-
sfernandez
Site Admin
- Posts: 2056
- Joined:
Re: How to find the control in the ItemsControls in C++?
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:
I guess you want this instead:
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:
And this translates to Noesis C++ like this:
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:
Code: Select all
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
- ...
Code: Select all
<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>
Code: Select all
var container = _itemsControl.ItemContainerGenerator.ContainerFromItem(dahCurrentItem) as ContentPresenter;
var checkBox = container.ContentTemplate.FindName("MyCheckBox", container) as CheckBox;
Code: Select all
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