DominikRuta
Topic Author
Posts: 3
Joined: 19 Dec 2023, 15:03

LocTable propagation to ContentControl's content via TemplateBinding

11 Apr 2024, 14:38

Hello, in Unreal project, I have a problem with propagating LocTable to ContentControl's content. Am I'm missing something or using bad approach?

I have created custom ContentControl called MainLayout which is suppose to represent main screen layout. This control has three dependency properties - HeaderContent, BodyContent and FooterContent. This content control has default style:
<Style TargetType="{x:Type layouts:MainLayout}">
	<Setter Property="Template">
		<Setter.Value>
			<ControlTemplate TargetType="{x:Type layouts:MainLayout}">
				<Grid>
					.... 						
					<ContentControl Focusable="False" Grid.Row="0" Content="{TemplateBinding HeaderContent" />
					<ContentControl Focusable="False" Grid.Row="1" Content="{TemplateBinding BodyContent}" />
					<ContentControl Focusable="False" Grid.Row="2" Content="{TemplateBinding FooterContent}" />
				</Grid>
			</ControlTemplate>
		</Setter.Value>
	</Setter>
</Style>
In that style I have three ContentControls, each dedicated to hold each container's content. Then I have UserControl which defines content for each of this section. Like this:
<Grid noesis:LocTable.Id="LocTableId">
    ....
   <TextBlock Text="{noesis:LocTable 'Title', Key=ScreenTitle}" />
   <layouts:MainLayout>
       <layouts:MainLayout.HeaderContent>
             <Grid>
                 <TextBlock Text="{noesis:LocTable 'Title', Key=ScreenTitle}" />
            </Grid>
        </layouts:MainLayout.HeaderContent>
   </layouts:MainLayout>
</Grid>
As you can see I have a main Grid, which has set LocTable.Id, so the whole scope of the grid references that table. Then I set content for the Header section. Now the problem is, that while outside the layouts:MainLayout control the text gets translated, inside layouts:MainLayout.HeaderContent does not. Content of that ContentControl on which is binded HeaderContent does not have that Id property set. However layouts:MainLayout does have that Id, so If I put some TextBlock inside that default style's ControlTemplate, it works.

Also when I do this, it also works:
<ContentControl Focusable="False" Grid.Row="0">
   <ContentControl.Content>
     <Grid>
        <TextBlock Text="{noesis:LocTable 'Title', Key=ScreenTitle}" />
     </Grid>
   </ContentControl.Content>
</ContentControl>

Do you know what might be the issue?
 
User avatar
sfernandez
Site Admin
Posts: 3027
Joined: 22 Dec 2011, 19:20

Re: LocTable propagation to ContentControl's content via TemplateBinding

19 Apr 2024, 12:36

Hello, sorry for the late reply.

I think the problem is that your MainLayout properties are not connected to the logical tree, so context is not properly inherited or markup extensions can't traverse the tree up as expected.

Do you have a property changed callback for those properties? You should connect the content to the logical tree as follows.
static void OnHeaderContentChanged(DependencyObject* d, const DependencyPropertyChangedEventArgs& e)
{
  MainLayout* main = (MainLayout*)d;
  BaseComponent* oldHeader = e.OldValue<Ptr<BaseComponent>>();
  if (oldHeader != nullptr) RemoveLogicalChild(oldHeader);
  BaseComponent* newHeader = e.NewValue<Ptr<BaseComponent>>();
  if (newHeader != nullptr) AddLogicalChild(newHeader);
}
Could you try that?
 
DominikRuta
Topic Author
Posts: 3
Joined: 19 Dec 2023, 15:03

Re: LocTable propagation to ContentControl's content via TemplateBinding

15 May 2024, 13:19

Hey, same apologize for the late response.

I've tried your solution and it works! Thanks a lot!
 
User avatar
sfernandez
Site Admin
Posts: 3027
Joined: 22 Dec 2011, 19:20

Re: LocTable propagation to ContentControl's content via TemplateBinding

15 May 2024, 21:22

Great, marking this as solved.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 8 guests