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は実際にはその幅を指定された値に変更しますが、そのアイテムはまだスケーリングされていません。