zoukankan      html  css  js  c++  java
  • WPF绑定.NET对象(二)Visifire的数据绑定

    Visifire在visifire_v3.6.8之前授权都是GPL v3的,而且也算是比较强大的chart插件。

    之前有写过WPF绑定.NET对象属性简单实例

    这里实战,因为项目用到,顺便这里做个笔记。

    Visifire数据绑定的方式:<Window x:Class="DataBindingInWPFVisifireChart.MainWindow"

            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="400" Width="580"
            xmlns:vc="clr-namespace:Visifire.Charts;assembly=WPFVisifire.Charts"
            >
        <Grid>
            <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center"  >
    
                <vc:Chart Name="MyChart" Width="500" Height="300" Padding="10,10" Margin="10,0" AnimatedUpdate="True" Theme="Theme5">
    
                    <vc:Chart.Titles>
                        <vc:Title Text="Visifire DataBinding"></vc:Title>
                    </vc:Chart.Titles>
    
                    <vc:Chart.Series>
                        <vc:DataSeries RenderAs="StackedArea" >
                            <vc:DataSeries.DataMappings>
                                <vc:DataMapping MemberName="AxisXLabel" Path="Label"></vc:DataMapping>
                                <vc:DataMapping MemberName="YValue" Path="YValue"></vc:DataMapping>
                            </vc:DataSeries.DataMappings>
                        </vc:DataSeries>
                    </vc:Chart.Series>
                </vc:Chart>
    
                <Button Margin="10" Click="Button_Click" Width="80">add</Button>
           <Button Margin="10" Click="Button1_Click" Width="80">remove</Button>
    </StackPanel> </Grid> </Window>

    要绑定的对象设计:

    namespace DataBindingInWPFVisifireChart
    {
        public class ValuesCollection : ObservableCollection<Value> { };
    
        public class Value : INotifyPropertyChanged
        {
            #region INotifyPropertyChanged Members
            public event PropertyChangedEventHandler PropertyChanged;
            #endregion
    
            Double _yValue;
            String _label;
    
            public String Label
            {
                get
                {
                    return _label;
                }
                set
                {
                    _label = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Label"));
                }
            }
    
            public Double YValue
            {
                get
                {
                    return _yValue;
                }
                set
                {
                    _yValue = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("YValue"));
                }
            }
        }
    }

    实现 INotifyPropertyChanged 接口和为绑定类型的每个属性提供更改事件,ok

    测试:

            public MainWindow()
            {
                InitializeComponent();
                values.Add(new Value() { Label = "Sony", YValue = 50 });
                values.Add(new Value() { Label = "Dell", YValue = 35 });
                values.Add(new Value() { Label = "HP", YValue = 27 });
                values.Add(new Value() { Label = "HCL", YValue = 17 });
                values.Add(new Value() { Label = "Toshiba", YValue = 16 });
    
                MyChart.Series[0].DataSource = values;
            }
    
            ObservableCollection<Value> values = new ObservableCollection<Value>();
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                values.Add(new Value() { Label = "add", YValue = 33.3 });
            }
    
            private void Button1_Click(object sender, RoutedEventArgs e)
            {
                if (values.Count > 0)
                {
                    values.RemoveAt(values.Count - 1);
                }
            }    

     

  • 相关阅读:
    autoMapper dotnetcore webapi 自动添加映射 abp
    win10安装MongoDB提示 the domain,user name and/or password are incorrect. Remember to use "." for the domain if the account is on the local machine.
    webapi 重复提交问题
    webapi postman 415 错误
    sqlserver 更新通过 select 查询出的结果集
    2016-03至2016-08前端工作总结
    css笔记——css 实现自定义按钮
    javascript笔记——date以及datetime的比较
    node.js笔记——gulp
    javascript笔记——密码组合规则
  • 原文地址:https://www.cnblogs.com/xiepeixing/p/2998116.html
Copyright © 2011-2022 走看看