CommunityToolkit/WindowsCommunityToolkit

HeaderedContentControl Templates binding with `<Run/>`

Open

#3945 aperta il 17 apr 2021

Vedi su GitHub
 (6 commenti) (0 reazioni) (0 assegnatari)C# (1403 fork)batch import
bug :bug:controls :control_knobs:good first issuehelp wanted

Metriche repository

Star
 (5708 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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):

image

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: )

Guida contributor