leonid_golovko
Topic Author
Posts: 13
Joined: 13 Jun 2024, 15:06

Initiate user control in xaml

01 Aug 2024, 07:42

<ItemsControl x:Name="IncisionsItemsControl" ItemsSource="{Binding Incisions}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <local:IncisionUserControl DataContext="{Binding}" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
I have a problem with initiating the user control of IncisionUserControl. They are NULL now. How should i make it work? Does it load when we initiate the data or at loaded time?(this->Loaded() += [this](BaseComponent* sender, const Noesis::RoutedEventArgs& args) {})
 
User avatar
sfernandez
Site Admin
Posts: 3112
Joined: 22 Dec 2011, 19:20

Re: Initiate user control in xaml

01 Aug 2024, 10:43

The user control specified in an ItemsControl item template will be instantiated for each item in the collection, and Initialized or Loaded events will be raised for each of the instantiated user controls.

What kind of extra initialization do you need to perform on your user control? The control should have the data context with the item view model set, so it has access to all the properties defined in the item view model.

Who is online

Users browsing this forum: No registered users and 3 guests