【问题标题】:WinRTXamlToolkit TreeView item stretch horizontallyWinRTXamlToolkit TreeView 项目水平拉伸
【发布时间】:2015-02-16 13:17:11
【问题描述】:

我正在尝试使树视图项目水平拉伸 这是我原来的结果 但我想要的是这个

这是我的 XAML 代码

<Grid x:Name="AgendaGrid" Grid.Row="1">
            <Controls:TreeView ItemsSource="{Binding TreeItems}" Style="{StaticResource TouchTreeViewStyle}">
                <Controls:TreeView.ItemTemplate>
                    <DataTemplate>
                        <data:DataTemplateExtensions.Hierarchy>
                            <data:HierarchicalDataTemplate ItemsSource="{Binding Children}" />
                        </data:DataTemplateExtensions.Hierarchy>


    <Grid>
        <Button Visibility="{Binding IsHeading}" Padding="0" Content="{Binding Name}" />
  </Grid> 
                    </DataTemplate>
                </Controls:TreeView.ItemTemplate>
            </Controls:TreeView>
        </Grid>

【问题讨论】:

    标签: wpf xaml windows-store-apps treeview winrt-xaml


    【解决方案1】:

    实现您想要的简单方法是使用HorizontalContentAlignment 属性:

    <TreeView ItemsSource="{Binding Items}" HorizontalContentAlignment="Stretch" />
    

    很遗憾,这不适用于TreeViewItem。这是因为TreeViewItemControlTemplate 具有硬编码的顶级Grid,它为此要求设置了错误的RowDefinitions。因此,满足您要求的方法是更改​​默认的ControlTemplate,您可以在 MSDN 上的TreeView Styles and Templates 页面中找到它。

    与其在此重复整个故事,我更愿意在 LeeCampbell 的博客Horizontal stretch on TreeViewItems 页面上为您提供解决方案。这更详细地描述了问题,并提出了对ControlTemplate 进行简单调整的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-20
      • 1970-01-01
      • 2020-01-25
      • 1970-01-01
      • 1970-01-01
      • 2017-06-04
      • 2016-10-27
      • 2011-03-29
      相关资源
      最近更新 更多