の方が簡単かもしれませんが、簡単にプレイし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; }
}
幸運を :)