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

时间:2018-06-13 11:56:42

标签: c++ text uwp treeview bold

我正在关注Microsoft's documentation irb(main):060:0> b[1].push(b[0].pop)=> [1, 1, 0, 1] 的{​​{1}}应用中实施(irb(main):061:0> b[0] - [1,0]).count (irb(main):061:0> b[0] - [1,1]).count (irb(main):061:0> b[0] - [0,1]).count 。我已经成功地使用以下代码创建了一个节点的树视图:

XAML:

TreeView

C ++:

Universal Windows Platform

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

C++

代码以粗体显示<TreeView x:Name="treeSolution"></TreeView> 而不是TreeViewNode ^treeNode = ref new TreeViewNode(); treeNode->Content = "Hello"; treeSolution->RootNodes->Append(treeNode);

文档说TextBlock ^textBlock = ref new TextBlock(); textBlock->Text = "Hello"; textBlock->FontWeight = Windows::UI::Text::FontWeights::Bold; treeNode->Content = textBlock; treeSolution->RootNodes->Append(treeNode); 然后使用音乐和图片库给出一个复杂的例子。

有人可以提供一个如何以粗体显示文本的简单示例吗?谢谢。

1 个答案:

答案 0 :(得分:0)

您必须为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>