0

SDKの基本的なTreeViewに基づいてカスタムTreeViewを作成するように依頼されました。それはすべて機能します。問題は次のとおりです。ノード/リーフはコンテンツに拡大されず、幅は常に同じです。xamlマークアップは次のとおりです。

<Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
      xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'                                                    xmlns:sdk='http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk'>
      <Grid.Resources>
          <Style x:Key='TreeViewChildStyle' TargetType='sdk:TreeViewItem'>
             <Setter Property='HorizontalContentAlignment' Value='Stretch'/>
             <Setter Property='Background' Value='Blue'/>
          </Style>
      <sdk:HierarchicalDataTemplate x:Key='ChildTemplate' x:Name='ChildTemplate'>
             <TextBlock HorizontalAlignment='Stretch' Text='{Binding Path=ChildPath}'/>  
          </sdk:HierarchicalDataTemplate>
      <sdk:HierarchicalDataTemplate x:Key='NameTemplate' ItemsSource='{Binding Path=   ChildrenCollectionPath}' x:Name='NameTemplate' ItemTemplate='{StaticResource ChildTemplate}'>
             <TextBlock HorizontalAlignment='Stretch' Text='{Binding Path=ParentPath}' Width='1000'/>
      </sdk:HierarchicalDataTemplate>
      </Grid.Resources>
      <sdk:TreeView Height='Auto' Background='Red' ItemContainerStyle='{StaticResource TreeViewChildStyle}' Name='treeView1' ItemTemplate='{StaticResource NameTemplate} VerticalAlignment='Stretch' HorizontalAlignment='Stretch' BorderThickness='0'/> 
</Grid>

コードビハインドでItemContainerの幅を設定し、TextBlocksの幅を「Auto」に設定し、スタイルマークアップでItemContainerの幅を設定してみました。何も機能しません。TreeViewItemsは常に同じ幅であり、狭すぎます。

編集:はい、グリッドに追加されたSDK名前空間があります。エディターに何かが起こっただけで、表示されません。それを助けることはできません。

Edit2:TreeViewは実際にはその幅を指定された値に変更しますが、そのアイテムはまだスケーリングされていません。

4

1 に答える 1

0

グリッドの行または列を定義し、高さ/幅を「*」に設定して、できるだけ多くのスペースを使用できるようにしてください。

<Grid.RowDefintions>
     <RowDefintion Height="*" />
</Grid.RowDefintions>

<Grid.ColumnDefinitons>
     <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
于 2013-03-05T11:21:56.647 に答える