CircularGauge - 简单绑定不起作用

时间:2017-03-20 15:29:52

标签: c# wpf binding

我有一个CircularGauge,范围从0到150.

仅用于演示我想将当前值绑定到随机值。该属性正在发生变化,但不会影响UI。有什么想法吗?

XAML:

    <Window x:Class="Gauge_3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Gauge_3"
        xmlns:gc="clr-namespace:CircularGauge;assembly=CircularGauge"
        mc:Ignorable="d"
        Title="MainWindow" Height="auto" Width="auto">
    <Grid>
        <gc:CircularGaugeControl x:Name="cControl"
            GaugeBackgroundColor="LightGreen" MinValue="0" 
                                 VerticalAlignment="Top"
                                 MaxValue="150" Radius="150" RangeIndicatorRadius="130" 
                                 RangeIndicatorThickness="10"
                                 OptimalRangeStartValue="50" OptimalRangeEndValue="85"
                                 DialTextColor="Black"
                                 DialText="Produktion"
                                 DialTextOffset="30"
                                 ScaleStartAngle="-210" 
                                 ScaleSweepAngle="240"
                                 MajorTickColor="Transparent"
                                 MinorTickColor="Transparent"
                                 ScaleLabelForeground="Transparent"
                                 CurrentValue="{Binding PercentValue}"
                                 PointerLength="110"
            Background="Transparent"                                      ImageSource="images/AW_Logo.png"
                                 ImageSize="60,60"
                                 ImageOffset="80">
</gc:CircularGaugeControl>
    </Grid>
</Window>

.cs文件

    namespace Gauge_3
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {

        private Timer aTimer;

        private double _PercentValue = 120;
        public double PercentValue
        {
            get { return _PercentValue; }
            set { _PercentValue = value; this.OnPropertyChanged("PercentValue"); }
        }


        public MainWindow()
        {
            InitializeComponent();
            cControl.DataContext = this;
            aTimer = new System.Timers.Timer(1000 * 2);
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            aTimer.Enabled = true;
        }

        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            Random rdPercent = new Random();
            PercentValue = rdPercent.Next(70, 145);
        }



        #region INotifyPropertyChanged members

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }            
}

我也尝试通过点击按钮来更改值,但没有任何反应。

0 个答案:

没有答案