Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ UWP:在TreeNode中将文本设置为粗体_C++_Text_Uwp_Treeview_Bold - Fatal编程技术网

C++ UWP:在TreeNode中将文本设置为粗体

C++ UWP:在TreeNode中将文本设置为粗体,c++,text,uwp,treeview,bold,C++,Text,Uwp,Treeview,Bold,我将在C++中的universalwindows平台应用程序中实现TreeView。我已经成功地使用以下代码创建了一个具有一个节点的树状视图: XAML: 现在,我想将文本设置为粗体。我尝试了以下方法: TextBlock ^textBlock = ref new TextBlock(); textBlock->Text = "Hello"; textBlock->FontWeight = Windows::UI::Text::FontWeights::Bold; treeNode-

我将在
C++
中的
universalwindows平台
应用程序中实现
TreeView
。我已经成功地使用以下代码创建了一个具有一个节点的树状视图:

XAML:

现在,我想将文本设置为粗体。我尝试了以下方法:

TextBlock ^textBlock = ref new TextBlock();
textBlock->Text = "Hello";
textBlock->FontWeight = Windows::UI::Text::FontWeights::Bold;
treeNode->Content = textBlock;
treeSolution->RootNodes->Append(treeNode);
代码以粗体显示
Windows.UI.Xaml.Controls.TextBlock
而不是
Hello

文档中说,
在Windows10版本1803中,如果内容不是字符串,则必须重新模板化TreeView控件并指定自定义ItemTemplate。
然后给出了使用音乐和图片库的复杂示例


有人能提供一个简单的例子,说明如何用粗体显示文本吗?谢谢

必须在XAML中为整个控件提供自定义样式,才能设置
TreeViewItemDataTemplate

<DataTemplate x:Key="TreeViewItemDataTemplate">
    <Grid Height="44">
        <TextBlock
            Text="{Binding Content}"
            HorizontalAlignment="Left"
            VerticalAlignment="Center"
            Style="{ThemeResource BodyTextBlockStyle}"
            FontWeight="Bold" />
    </Grid>
</DataTemplate>

<Style TargetType="TreeView">
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TreeView">
                <TreeViewList x:Name="ListControl"
                              ItemTemplate="{StaticResource TreeViewItemDataTemplate}"
                              ItemContainerStyle="{StaticResource TreeViewItemStyle}"
                              CanDragItems="True"
                              AllowDrop="True"
                              CanReorderItems="True">
                    <TreeViewList.ItemContainerTransitions>
                        <TransitionCollection>
                            <ContentThemeTransition />
                            <ReorderThemeTransition />
                            <EntranceThemeTransition IsStaggeringEnabled="False" />
                        </TransitionCollection>
                    </TreeViewList.ItemContainerTransitions>
                </TreeViewList>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

谢谢!对于其他有相同问题的人,我在
中添加了这些代码。我还必须清理项目。
TextBlock ^textBlock = ref new TextBlock();
textBlock->Text = "Hello";
textBlock->FontWeight = Windows::UI::Text::FontWeights::Bold;
treeNode->Content = textBlock;
treeSolution->RootNodes->Append(treeNode);
<DataTemplate x:Key="TreeViewItemDataTemplate">
    <Grid Height="44">
        <TextBlock
            Text="{Binding Content}"
            HorizontalAlignment="Left"
            VerticalAlignment="Center"
            Style="{ThemeResource BodyTextBlockStyle}"
            FontWeight="Bold" />
    </Grid>
</DataTemplate>

<Style TargetType="TreeView">
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TreeView">
                <TreeViewList x:Name="ListControl"
                              ItemTemplate="{StaticResource TreeViewItemDataTemplate}"
                              ItemContainerStyle="{StaticResource TreeViewItemStyle}"
                              CanDragItems="True"
                              AllowDrop="True"
                              CanReorderItems="True">
                    <TreeViewList.ItemContainerTransitions>
                        <TransitionCollection>
                            <ContentThemeTransition />
                            <ReorderThemeTransition />
                            <EntranceThemeTransition IsStaggeringEnabled="False" />
                        </TransitionCollection>
                    </TreeViewList.ItemContainerTransitions>
                </TreeViewList>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>