FrameworkElement.Parent property null when used in a template
I'm having an issue where I have a custom control registering to events on the parent element, and sending it on a message bus type architecture.
Everything works fine, except when I am using this custom control inside a template: In this case, the property 'Parent' in the codebehind is null and never set.
Am I doing something wrong? Where could the issue be?
Thanks a lot,
Pierre
Everything works fine, except when I am using this custom control inside a template: In this case, the property 'Parent' in the codebehind is null and never set.
Code: Select all
<Expander ExpandDirection="Up" Grid.Column="1" Header="THINGS" VerticalAlignment="Bottom">
<ItemsControl ItemsSource="{Binding BottomMenuBarViewModels}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type vm:BottomMenuBarViewModel}">
<Border>
<Button>
<views:MessagingView Event="Click">
Send message!
</views:MessagingView >
</Button>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Expander>
Thanks a lot,
Pierre
-
sfernandez
Site Admin
- Posts: 2995
- Joined:
Re: FrameworkElement.Parent property null when used in a template
Have you tried to check the Parent on the Loaded event of your MessageView code-behind?
This event is called after element gets layout, so it should be connected to the tree and Parent property correctly set.
This event is called after element gets layout, so it should be connected to the tree and Parent property correctly set.
Who is online
Users browsing this forum: No registered users and 4 guests