1
我似乎無法將Header綁定到我創建的樹視圖的樣式 我有點兒把這個控件大聲說出來。創建該節點是風格節點使用XAML綁定時遇到問題
<HierarchicalDataTemplate x:Key="WizardsMenuItem" >
<TreeViewItem ClipToBounds="True">
<TreeViewItem.HeaderTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem}, Path=IsExpanded}">
<CheckBox.Template>
<ControlTemplate>
<DockPanel MaxWidth="365">
<Border Margin="5" Height="80" BorderBrush="Black" BorderThickness="1" CornerRadius="5" >
<DockPanel>
<DockPanel>
<DockPanel Name="IconArea" DockPanel.Dock="Right">
<Border Margin="4" Width="80" BorderBrush="Black" BorderThickness="1" CornerRadius="5" DockPanel.Dock="Right">
<Image />
</Border>
</DockPanel>
<DockPanel Name="TextArea" DockPanel.Dock="Left">
<TextBlock Text="{Binding}" Foreground="Black" DockPanel.Dock="Top" Margin="3,10,3,10" FontSize="18" FontWeight="Bold" FontFamily="Tahoma" />
<TextBlock Text="Basic Hardware, Disk Drive Space, Memory Size, Memory Allocation"
DockPanel.Dock="Top"
Margin="13,0,0,0"
FontFamily="Verdana" FontSize="9"
TextWrapping="Wrap" />
</DockPanel>
</DockPanel>
</DockPanel>
</Border>
</DockPanel>
</ControlTemplate>
</CheckBox.Template>
</CheckBox>
</DataTemplate>
</TreeViewItem.HeaderTemplate>
<TreeViewItem>
<TreeViewItem.HeaderTemplate>
<DataTemplate>
<Border Margin="30,0,5,0" BorderBrush="Black" BorderThickness="1" CornerRadius="5" >
<DockPanel>
<Button DockPanel.Dock="Top" Margin="5,2,5,2" Content="Predefined Reports" Background="Transparent" BorderBrush="Transparent" />
<Button DockPanel.Dock="Top" Margin="5,2,5,2" Content="Favorites Reports" Background="Transparent" BorderBrush="Transparent" />
<Button DockPanel.Dock="Top" Margin="5,2,5,2" Content="Customize Reports" Background="Transparent" BorderBrush="Transparent" />
</DockPanel>
</Border>
</DataTemplate>
</TreeViewItem.HeaderTemplate>
</TreeViewItem>
</TreeViewItem>
</HierarchicalDataTemplate>
一切工作,除了此位
<TextBlock Text="{Binding}" Foreground="Black" DockPanel.Dock="Top" Margin="3,10,3,10"
FontSize="18" FontWeight="Bold" FontFamily="Tahoma" />
我希望有人可以幫我
代碼
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="12*" MaxWidth="400"/>
<ColumnDefinition Width="13*"/>
</Grid.ColumnDefinitions>
<TreeView Name="WizardMenu" Visibility="Collapsed">
<TreeViewItem Name="treeViewItem" IsExpanded="True"
Header="Hardware Information"
HeaderTemplate="{StaticResource WizardsMenuItem}"
>
</TreeViewItem>
<TreeViewItem Name="treeViewItem1" IsExpanded="True"
Header="Hardware Information"
HeaderTemplate="{StaticResource WizardsMenuItem}"
>
</TreeViewItem>
<TreeViewItem Name="treeViewItem2" IsExpanded="True"
Header="Hardware Information"
HeaderTemplate="{StaticResource WizardsMenuItem}"
>
</TreeViewItem>
</TreeView>
代碼
預先感謝您:)
呀這就是它幹了什麼 <樹型視圖ClipToBounds = 「真」 標題= 「{結合}」> –
如果您再次閱讀這篇文章,我不確定如何按照您的建議設計Treeview風格。我基本上在節點級別上有不同的模板。第一級是動態的,第二級是靜態的(第二級上的所有節點完全一樣) –
沒關係,我想通了。再次感謝你 –