WindowsCommunityToolkit
WindowsCommunityToolkit copied to clipboard
HeaderedContentControl Templates binding with `<Run/>`
Describe the bug
When styling the HeaderTemplate
or ContentTemplate
of the HeaderedContentControl
, if the text of any of them is set with the <Run/>
blocks instead of directly as a string or a single binding
, the text is not displayed.
Steps to Reproduce
This can be reproduced just with this little XAML snippet. Just create a HeaderedContentControl
with custom styles for both the Header and the Content; one of them passing as a single string inline, and the other one as <Run/>
blocks.
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<Style TargetType="controls:HeaderedContentControl">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" Opacity="0.6"/>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<controls:HeaderedContentControl Header="Hello world" Margin="100 0">
<controls:HeaderedContentControl.Content>
<TextBlock>
<Run Text="testing"/><Run Text="testing"/>
</TextBlock>
</controls:HeaderedContentControl.Content>
</controls:HeaderedContentControl>
</Page>
The result of this snippet is the following (tried both in Visual Studio, and in XAML studio just in case):
Expected behavior
Expected behaviour would be the text to be displayed correctly, instead of displaying the object of the page.
Environment
Package Version(s): 7.0.1
Windows 10 Build Number: 19042:928 (20H2)
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [x] May 2020 Update (19041)
- [ ] Insider Build (build number: )
App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [x] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [x] May 2020 Update (19041)
- [ ] Insider Build (xxxxx)
Device form factor:
- [x] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT
Visual Studio
- [ ] 2017 (version: )
- [x] 2019 (version: )
- [ ] 2019 Preview (version: )
Hello ismaelestalayo, thank you for opening an issue with us!
I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌
By suggestion of @michael-hawker himself on the UWP discord, I copied the whole template of HeaderedContentControl
from your repo into my style as a workaround and it works.
@ismaelestalayo Thanks for showing interest here and finding a bug. Do you want to create a PR and will test it out?
Yeah, looks like this may be an issue with us not properly templatebinding to the required properties.
I'd totally do it, the thing is I dont really know what exactly is there to change in the file HeaderedContentControl.xaml or why adding the exact same template in my page fixed the problem.
I feel like part of the problem could be the content template is a TextBlock
accepting a binding, and then the content itself is being set as another TextBlock
, so that could be causing some issues.
@niels9001 I know we're revamping this for 8.0, so something or us to keep in mind or at least potentially show some examples of overriding different parts of the templates.