简体   繁体   English

如何在WPF中创建探查器GUI?

[英]How can I create a profiler GUI in WPF?

I am looking to create a task profiler in WPF with an UI similar to the one of incredibuild. 我希望在WPF中使用类似于incredibuild的UI创建任务分析器。

Eg, timed tasks appear as strips on their respective line. 例如,定时任务在其各自的行上显示为带状。 Have a look at: 看一下:

http://baoz.net/wp-content/2009/06/ib1.png http://baoz.net/wp-content/2009/06/ib1.png

to see what I mean. 明白我的意思。 I am unsure what the best way to tackle this problem is? 我不确定解决此问题的最佳方法是什么? Should I override the Panel class creating a custom layout panel for this or might there be an existing control/library out there that can fit my needs. 我应该重写Panel类来为此创建一个自定义布局面板,还是应该有一个适合我需要的现有控件/库。 I have so far had a look at various charting controls but am unsure of weither they can be tweaked to achieve this behaviour or not. 到目前为止,我已经看过各种图表控件,但是不确定是否可以对其进行调整以实现此行为。 I am really hoping for someone who has been using WPF for a while to help me narrow down my search. 我真的希望有一个使用WPF已有一段时间的人来帮助我缩小搜索范围。 It is not exactly easy to know what to google for either :) 都不知道要用Google做什么是很不容易的:)

In WPF this kind of chart is absolutely trivial. 在WPF中,这种图表绝对是微不足道的。 No special charting package is required: 不需要特殊的图表软件包:

In your resources, define a DataTemplate for displaying the event whose width is bound to the event length: 在您的资源中,定义一个DataTemplate来显示事件,该事件的宽度与事件长度绑定:

  <DataTemplate TargetType="{x:Type local:Event}">
    <Border Width="{Binding EventLength}">  <!-- This sets the width -->
      <Border Margin="1" Padding="1" StrokeThickness="1" Stroke="Black"
              Background="{Binding EventColor}"> <!-- Actual border -->
        <TextBlock Text="{Binding EventDescription}" />
      </Border>
    </Border>
  </DataTemplate>

Also define a horizontal items panel template: 还定义一个水平项目面板模板:

  <ItemsPanelTemplate x:Key="HorizontalPanel"><DockPanel/></ItemsPanelTemplate>

Now your actual chart is trivial to build: 现在,您的实际图表构建起来很简单:

<ItemsControl ItemsSource="{Binding CPUs}">
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <DockPanel>
        <TextBlock Width="100" Text="{Binding Name}" /> <!-- CPU name -->
        <Rectangle Width="1" Fill="Black" />            <!-- Vertical divider -->
        <ItemsControl ItemsSource="{Binding Events}"    <!-- Events -->
                      ItemsPanel="{StaticResource HorizontalPanel}" />
      </DockPanel>
    </DataTemplate>
  </ItemsControl.Template>
</ItemsControl>

If you have gaps between your events, simply add a "Gap" object to your Events collection to represent them, then add a DataTemplate for gaps: 如果事件之间存在间隙,则只需在“事件”集合中添加一个“间隙”对象来表示它们,然后为间隙添加一个DataTemplate:

<DataTemplate TargetType="{x:Type local:Gap}">
  <UIElement Width="{Binding GapWidth}" />
</DataTemplate>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM