CommunityToolkit/WindowsCommunityToolkit

HeaderedContentControl Templates binding with `<Run/>`

Open

#3,945 创建于 2021年4月17日

在 GitHub 查看
 (6 评论) (0 反应) (0 负责人)C# (1,403 fork)batch import
bug :bug:controls :control_knobs:good first issuehelp wanted

仓库指标

Star
 (5,708 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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

贡献者指南