- DominikRuta
- Posts: 2
- Joined:
LocTable propagation to ContentControl's content via TemplateBinding
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:
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:
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:
Do you know what might be the issue?
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:
Code: Select all
<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>
Code: Select all
<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>
Also when I do this, it also works:
Code: Select all
<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?
-
sfernandez
Site Admin
- Posts: 3008
- Joined:
Re: LocTable propagation to ContentControl's content via TemplateBinding
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.
Could you try that?
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.
Code: Select all
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);
}
Who is online
Users browsing this forum: Semrush [Bot] and 10 guests