Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight TreeView项目宽度更改_Silverlight_Xaml_Treeview_Treeviewitem - Fatal编程技术网

Silverlight TreeView项目宽度更改

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'

我被要求根据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>


尝试定义网格行或列,并将高度/宽度设置为“*”,以便尽可能多地使用空间

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

<Grid.ColumnDefinitons>
     <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

尝试在“sdk:HierarchycalDataTemplate”中使用网格,然后在其中使用文本块。并将该网格中的RowDefinition和ColumnDefinition设置为“*”仍然不是它。我要试试ScaleToContent的东西。