8,731
社区成员
发帖
与我相关
我的任务
分享
<Window x:Class="WebSiteFavorite.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WebSiteFavorite"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" WindowStartupLocation="CenterScreen" Height="600" Width="800" Loaded="Window_Loaded">
<Window.Resources>
<HierarchicalDataTemplate x:Key="TreeViewTemplate" DataType="{x:Type local:PropertyNodeItem}" ItemsSource="{Binding
Children}">
<StackPanel>
<Image/>
<TextBlock Text="{Binding DisplayName}"/>
<StackPanel.ToolTip>
<TextBlock Text="{Binding FileSystemInfo.FullName}"/>
</StackPanel.ToolTip>
</StackPanel>
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="50"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition MinWidth="100"/>
</Grid.ColumnDefinitions>
<DockPanel>
<TreeView Name="tvFavorite" TreeViewItem.Selected="tvFavorite_Selected" ItemTemplate="{StaticResource
TreeViewTemplate}" FontSize="15">
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="False"/>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem Name="tvcmAdd" Header="添加" Click="tvcmAdd_Click"/>
<MenuItem Name="tvcmDelete" Header="删除"/>
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</DockPanel>
<GridSplitter Grid.Column="1" HorizontalAlignment="Center" Width="5" Background="#BBB"/>
</Grid>
</Grid>
</Window>
public class PropertyNodeItem
{
string icon = "";
public string Icon
{
get { return icon; }
set
{
icon = value;
}
}
string displayName = "";
public string DisplayName
{
get { return displayName; }
set
{
displayName = value;
}
}
bool isExpanded = false;
public bool IsExpanded
{
get { return isExpanded; }
set { isExpanded = value; }
}
FileSystemInfo fileSystemInfo = null;
public FileSystemInfo FileSystemInfo
{
get { return fileSystemInfo; }
set
{
fileSystemInfo = value;
}
}
private ObservableCollection<PropertyNodeItem> children = new ObservableCollection<PropertyNodeItem>();
public ObservableCollection<PropertyNodeItem> Children
{
get { return children; }
set { children = value; }
}
}
}