Topic Author
Posts: 14
Joined: 15 May 2017, 19:19

FrameworkElement.Parent property null when used in a template

11 Jul 2017, 01:16

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.
<Expander ExpandDirection="Up" Grid.Column="1" Header="THINGS" VerticalAlignment="Bottom">
		<ItemsControl ItemsSource="{Binding BottomMenuBarViewModels}">
				<DataTemplate DataType="{x:Type vm:BottomMenuBarViewModel}">
							<views:MessagingView  Event="Click">
								Send message!
							</views:MessagingView >
Am I doing something wrong? Where could the issue be?
Thanks a lot,

User avatar
Site Admin
Posts: 3064
Joined: 22 Dec 2011, 19:20

Re: FrameworkElement.Parent property null when used in a template

14 Jul 2017, 02:27

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.

Who is online

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