0

我有一个带有网格的silverlight3.0 应用程序。XAML 如下。当用户更改左列的宽度时,我希望调整 TreeView 控件的大小和包装内容。目前,树视图显示滚动条而不是换行。在右栏中,这工作正常,因为没有树视图但堆栈面板。

当我使用 HierarchicalDataTemplate 而不是静态树视图项时,也会发生同样的情况。

关于如何使这项工作的任何想法?

谢谢,-cc

  <Grid x:Name="LayoutRoot" Background="Aqua">


            <Grid.RowDefinitions>
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition  />
            </Grid.ColumnDefinitions>
        <StackPanel Orientation="Vertical" Grid.Column="0"  Background="Yellow">
            <controls:TreeView  >

                <controls:TreeViewItem Header="test1 some text some text some text some text some text">
                    <controls:TreeViewItem Header="test1.1 some text some text some text some text some text">
                    </controls:TreeViewItem>
                </controls:TreeViewItem>
                <controls:TreeViewItem    Header="test2 some text some text some text some text some text some text some text some text some text some text some text">
                    <controls:TreeViewItem Header="test2 some text some text some text some text some text some text some text some text some text some text some text">
                    </controls:TreeViewItem>

                </controls:TreeViewItem>
            </controls:TreeView>
        </StackPanel>
        <controls:GridSplitter Grid.Row="0" Grid.Column="1" Width="5" VerticalAlignment="Stretch" 
                                       HorizontalAlignment="Center" Background="AliceBlue"/>
        <StackPanel Grid.Column="2" Orientation="Vertical">
            <TextBlock TextWrapping="Wrap"> dwd kwdh wkd wkd wkd wkjd hwkdjhw kdw dkw k</TextBlock>
            <TextBlock TextWrapping="Wrap"> dwd kwdh wkd wkd wkd wkjd hwkdjdwd kwdh wkd wkd wkd wkjd hwkdjhw kdw dkw k</TextBlock>
        </StackPanel>
    </Grid>
4

1 回答 1

0

该死; 我来到这里寻找这个问题的答案。

我能做的最好的是将 TextBlock 的 MaxWidth 绑定到 TreeView 的大小,并提供一个偏移量。为 (WPF) TreeView 尝试这个 XAML,并摆脱封闭的 StackPanel:

    <TreeView>
        <TreeViewItem>

            <TreeViewItem.Header>
                <TextBlock
                    Text="Maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat "
                    Background="Azure"
                    TextWrapping="Wrap"
                    MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeView}}, Path=ActualWidth, Converter={StaticResource ValueSubtractor}, ConverterParameter=30}"
                />
            </TreeViewItem.Header>

            <TextBlock
                Text="Faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent ultrices"
                Background="#FFBDBDE6"
                TextWrapping="Wrap"
                MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeView}}, Path=ActualWidth, Converter={StaticResource ValueSubtractor}, ConverterParameter=50}"
            />

            <TextBlock
                Text="Placerat pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst"
                Background="#FF9090E0"
                TextWrapping="Wrap"
                MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeView}}, Path=ActualWidth, Converter={StaticResource ValueSubtractor}, ConverterParameter=50}"
            />

        </TreeViewItem>
    </TreeView>

您需要编写一个执行偏移量的值转换器,并确保树的每个级别的偏移量足够大,以便在滑动拆分器时不会出现水平滚动条。

我在使用这种技术时遇到的一个问题是,当我尝试对 HierarchicalDataTemplate 上的 MaxWidth 进行相同的绑定时,Blend 3 抱怨 XAML 无效并且我得到红色波浪线。它当然仍在运行,但我期待 Blend 的 XAML 解析器更新!

于 2010-01-22T05:30:01.707 回答