在图例框(ChartPlotter)WPF中添加垂直滚动

时间:2012-05-07 08:59:06

标签: c# wpf dynamic-data-display

我是WPF应用程序的新手。我正在研究传感器读取WPF应用程序。在这个应用程序中,我必须从170个传感器中选择传感器。当我点击查看报告选择传感器后,图表绘图仪绘制选定的图表sensors.It对我来说很好。

问题:

由于页面大小的限制,我有固定的图形高度。但是当传感器的数量超过图形的高度时,所选传感器的图例会隐藏那些未在图形高度调整的人。如何添加滚动到图例框,以便用户可以滚动并检查所有传感器图例。

请提出一些想法。

提前致谢。

2 个答案:

答案 0 :(得分:1)

我在网上搜索了很多这个问题,但我没有解决这个问题。所以为了解决这个问题,我按照这些步骤进行了。

1.)首先,我将绘图仪图例的可见性设为假    plotter.LegendVisible = false;

2.)其次,我首先在绘图仪图例出现的图形上添加一个listview控件。

  <ListView Height="Auto" HorizontalAlignment="Center" Margin="1100,139,0,0" Name="listview" ItemsSource="{Binding Items}" HorizontalContentAlignment="Stretch" VerticalAlignment="Top" Width="75" Grid.RowSpan="2" MaxHeight="260">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Text}" Foreground="{Binding BackgroundColor}">
                                    </TextBlock>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                            <ListView.BorderBrush>
                                <SolidColorBrush />
                            </ListView.BorderBrush>
                        </ListView>

3.)然后我在后端做一些工作 -

- 添加ItemVM.cs:

 class ItemVM : INotifyPropertyChanged
{
    private string TextValue = String.Empty;
    private Brush BackgroundColorValue = null;

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }

    public ItemVM(Brush color, string objectData)
    {
        BackgroundColor = color;
        Text = objectData;
    }
    public string Text
    {
        get
        {
            return this.TextValue;
        }

        set
        {
            if (value != this.TextValue)
            {
                this.TextValue = value;
                NotifyPropertyChanged("Text");
            }
        }
    }
    public Brush BackgroundColor
    {
        get
        {
            return this.BackgroundColorValue;
        }

        set
        {
            if (value != this.BackgroundColorValue)
            {
                this.BackgroundColorValue = value;
                NotifyPropertyChanged("BackgroundColor");
            }
        }
    }

}

-in mainform.xaml.cs:

 List<ItemVM> Items;
               List<string> lst = new List<string> {"item1","item2","item3" };
               var converter = new System.Windows.Media.BrushConverter();
  Color[] colors = ColorHelper.CreateRandomColors(3);
  Items = new List<ItemVM>();
 for(int i=0;i<lst.count;i++)
 {
 Items.Add(new ItemVM((Brush)converter.ConvertFromString(colors[i].ToString()), SelectedItems[i]));
}
 plotter.LegendVisible = false;
 listview.ItemsSource = Items;

现在我在图表绘图仪上有传说框,滚动和regend forecolor也反映了图表线颜色。

答案 1 :(得分:0)

使用ScrollViewer:

<ScrollViewer Height="whatever your graph height is">
  <ListView>
          ...Dynamically place all your sensors here from your Presenter or code-behind
  </ListView>
</ScrollViewer>

这应该照顾你。

相关问题