它可能會更容易Style
ListView
,我有一個快速發揮,並設法創建一個模型約10分鐘。
很明顯,你會希望添加更多,但它似乎很容易主辦TreeView
的ListView
柱內。
這裏是樣機代碼,如果你想使用的基礎上。
的XAML:
<Window x:Class="WpfApplication8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="233" Width="405" Name="UI">
<Grid DataContext="{Binding ElementName=UI}">
<ListView ItemsSource="{Binding Processes}" >
<ListView.View>
<GridView>
<GridViewColumn Header="Process" Width="200" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TreeView BorderThickness="0" ItemsSource="{Binding Processes}" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Processes}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="CPU" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding CpuUsage, StringFormat={}{0} %}" TextAlignment="Right" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Memory" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding MemUsage, StringFormat={}{0} MB}" TextAlignment="Right" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
</Window>
代碼:關於treeible模型數據加載:)對不起
public partial class MainWindow : Window
{
private ObservableCollection<ProcessInfo> _processes = new ObservableCollection<ProcessInfo>();
public MainWindow()
{
InitializeComponent();
Processes.Add(new ProcessInfo
{
CpuUsage = 10.3,
MemUsage = 48.9,
Processes = new ObservableCollection<Process>()
});
var pro = new Process{ Name = "Process1", Processes = new ObservableCollection<Process>()};
pro.Processes.Add(new Process { Name = "SubProcess1", Processes = new ObservableCollection<Process>() });
Processes[0].Processes.Add(pro);
Processes.Add(new ProcessInfo
{
CpuUsage = 0,
MemUsage = 100,
Processes = new ObservableCollection<Process>()
});
var pro2 = new Process { Name = "Process2", Processes = new ObservableCollection<Process>() };
pro2.Processes.Add(new Process { Name = "SubProcess1", Processes = new ObservableCollection<Process>() });
pro2.Processes.Add(new Process { Name = "SubProcess2", Processes = new ObservableCollection<Process>() });
pro2.Processes.Add(new Process { Name = "SubProcess3", Processes = new ObservableCollection<Process>() });
Processes[1].Processes.Add(pro2);
}
public ObservableCollection<ProcessInfo> Processes
{
get { return _processes; }
set { _processes = value; }
}
}
public class ProcessInfo
{
public ObservableCollection<Process> Processes { get; set; }
public double CpuUsage { get; set; }
public double MemUsage { get; set; }
}
public class Process
{
public string Name { get; set; }
public ObservableCollection<Process> Processes { get; set; }
}
祝你好運:)
+1家庭蓋伊參考:) – bouvierr
我沒」你知道,總是邪惡的。 –