Silverlight TreeView项目宽度更改
我被要求根据SDK中的基本TreeView创建自定义TreeView。这一切都是可行的,问题是:节点/叶子不会延伸到它们的内容,它们的宽度总是相同的。以下是xaml标记:Silverlight TreeView项目宽度更改,silverlight,xaml,treeview,treeviewitem,Silverlight,Xaml,Treeview,Treeviewitem,我被要求根据SDK中的基本TreeView创建自定义TreeView。这一切都是可行的,问题是:节点/叶子不会延伸到它们的内容,它们的宽度总是相同的。以下是xaml标记: <Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/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>
尝试定义网格行或列,并将高度/宽度设置为“*”,以便尽可能多地使用空间
<Grid.RowDefintions>
<RowDefintion Height="*" />
</Grid.RowDefintions>
<Grid.ColumnDefinitons>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
尝试在“sdk:HierarchycalDataTemplate”中使用网格,然后在其中使用文本块。并将该网格中的RowDefinition和ColumnDefinition设置为“*”仍然不是它。我要试试ScaleToContent的东西。