请教一个visifire的图表chart控件数据绑定问题。
一个listbox中,我手动绑定到一个 ObservableCollection<Interface>,Interface为自定义的数据类,也即为listboxitem的source。我手动在 ObservableCollection<Interface>添加一个项,为了测试chart绑定功能。前台代码为
<Window x:Class="chartBindingTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vc="clr-namespace:Visifire.Charts;assembly=WPFVisifire.Charts"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Title="MainWindow" Height="350" Width="525" DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid x:Name="grid">
<Grid.Resources>
<Style TargetType="{x:Type ListBox}" x:Key="listBoxStyle">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<vc:Chart x:Name="chart" LightingEnabled="False" CornerRadius="7" Theme="Theme4"
AnimationEnabled="False" Margin="5,0,5,5" Grid.Row="1" ScrollingEnabled="false" Width="500" Height="250" HorizontalAlignment="Stretch"
ShadowEnabled="False" BorderThickness="1" Grid.ColumnSpan="1" ZoomingEnabled="False" ZoomingMode="MouseWheel" PanningMode="ScrollBarAndMouseDrag" >
<vc:Chart.Titles>
<vc:Title Text="{Binding Title}"/>
</vc:Chart.Titles>
<vc:Chart.Series>
<vc:DataSeries DataPoints="{Binding DC}" LegendText="速率" XValueType="DateTime" RenderAs="Line" BubbleStyle="Style2"></vc:DataSeries>
</vc:Chart.Series>
<vc:Chart.AxesX>
<vc:Axis LineThickness="0" Interval="1" IntervalType="Seconds" ValueFormatString="mm:ss"/>
</vc:Chart.AxesX>
</vc:Chart>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition />
</Grid.RowDefinitions>
<ListBox Grid.Row="1" x:Name="listBox" Style="{StaticResource listBoxStyle}" />
<Button x:Name="test" Click="test_Click" Content="开始" Width="60" />
</Grid>
</Window>
后台为
using System;
using System.Windows;
using Visifire.Charts;
using System.Collections.ObjectModel;
namespace chartBindingTest
{
public partial class MainWindow : Window
{
ObservableCollection<Interface> interfaceList = new ObservableCollection<Interface>();
public MainWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
listBox.ItemsSource = interfaceList;
Interface i = new Interface();
interfaceList.Add(i);
}
private void test_Click(object sender, RoutedEventArgs e)
{
Interface i = interfaceList[0];
DataPoint dpIn = new DataPoint();
dpIn.XValue = new DateTime(2013, 1, 1, 12, 12, 12);
dpIn.YValue = 0.5;
DataPoint dpOut = new DataPoint();
dpOut.XValue = new DateTime(2013, 1, 1, 12, 12, 15);
dpOut.YValue = 0.8;
DataPoint dpOut1 = new DataPoint();
dpOut1.XValue = new DateTime(2013, 1, 1, 12, 12, 18);
dpOut1.YValue = 45;
i.DC.Add(dpIn);
i.DC.Add(dpOut);
i.DC.Add(dpOut1);
i.Title = "new title";
}
}
}
Interface类代码为
using Visifire.Charts;
using System.ComponentModel;
namespace chartBindingTest
{
class Interface : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string propName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
//DataPointCollection继承自ObservableCollection,不需要做更改通知。
DataPointCollection dc = new DataPointCollection();
public DataPointCollection DC
{
get { return dc; }
set {
dc = value;
}
}
string title = "title";
public string Title
{
get { return title; }
set { title = value;
NotifyPropertyChanged("Title");
}
}
}
}
运行后,点击按钮,titile能正常更新通知,但是图表就是不显现,按道理说绑定在了DataPointCollection上,是有通知功能的,不知道为什么,求教。
工程文件我上传到网盘了http://pan.baidu.com/share/link?shareid=2330603894&uk=2081194446 wpf visifire 控件 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 顶一下,求解!!! --------------------编程问答-------------------- --------------------编程问答-------------------- 给个网址你自己找找http://wenku.baidu.com/view/9dd88aea0975f46527d3e151.html,用过MSChart的
补充:.NET技术 , C#