Click here to Skip to main content
15,867,568 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Custom drawing ToggleButton when checked Pin
Gerry Schmitz17-Oct-22 10:11
mveGerry Schmitz17-Oct-22 10:11 
GeneralRe: Custom drawing ToggleButton when checked Pin
Maximilien24-Oct-22 2:48
Maximilien24-Oct-22 2:48 
QuestionReferencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 2:24
Maximilien5-Oct-22 2:24 
AnswerRe: Referencing DrawingImage in a binding. Pin
Richard Deeming5-Oct-22 5:29
mveRichard Deeming5-Oct-22 5:29 
GeneralRe: Referencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 7:14
Maximilien5-Oct-22 7:14 
GeneralRe: Referencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 7:55
Maximilien5-Oct-22 7:55 
QuestionDesign Question Pin
Kevin Marois2-Oct-22 11:13
professionalKevin Marois2-Oct-22 11:13 
AnswerRe: Design Question Pin
Gerry Schmitz2-Oct-22 15:47
mveGerry Schmitz2-Oct-22 15:47 
QuestionLooking for a WPF control. Pin
Maximilien22-Sep-22 8:40
Maximilien22-Sep-22 8:40 
AnswerRe: Looking for a WPF control. Pin
Richard Deeming22-Sep-22 21:39
mveRichard Deeming22-Sep-22 21:39 
GeneralRe: Looking for a WPF control. Pin
Maximilien23-Sep-22 1:33
Maximilien23-Sep-22 1:33 
GeneralRe: Looking for a WPF control. Pin
Maximilien23-Sep-22 1:54
Maximilien23-Sep-22 1:54 
QuestionWeird behavior with contextual menu not rendering properly. Pin
Maximilien21-Sep-22 7:00
Maximilien21-Sep-22 7:00 
AnswerRe: Weird behavior with contextual menu not rendering properly. Pin
Richard Deeming21-Sep-22 21:36
mveRichard Deeming21-Sep-22 21:36 
GeneralRe: Weird behavior with contextual menu not rendering properly. Pin
Maximilien22-Sep-22 8:22
Maximilien22-Sep-22 8:22 
QuestionConversion to .Net Core Issues Pin
Kevin Marois19-Sep-22 6:39
professionalKevin Marois19-Sep-22 6:39 
AnswerRe: Conversion to .Net Core Issues Pin
Richard Deeming19-Sep-22 21:20
mveRichard Deeming19-Sep-22 21:20 
GeneralRe: Conversion to .Net Core Issues Pin
Kevin Marois20-Sep-22 7:10
professionalKevin Marois20-Sep-22 7:10 
GeneralRe: Conversion to .Net Core Issues Pin
Kevin Marois22-Sep-22 5:57
professionalKevin Marois22-Sep-22 5:57 
GeneralRe: Conversion to .Net Core Issues Pin
Richard Deeming22-Sep-22 21:38
mveRichard Deeming22-Sep-22 21:38 
QuestionUsing Dependency Property's to Affect Non WPF Property's Pin
Marc Jeeves1-Sep-22 10:52
Marc Jeeves1-Sep-22 10:52 
AnswerRe: Using Dependency Property's to Affect Non WPF Property's Pin
Richard Deeming1-Sep-22 22:11
mveRichard Deeming1-Sep-22 22:11 
Marc Jeeves wrote:
public partial class WaitTicker_Control : UserControl, INotifyPropertyChanged
A DependencyObject such as a UserControl doesn't need to implement INotifyPropertyChanged. The DependencyProperty already raises the necessary events when the value changes.

You're passing in the current value of a DependencyProperty to the Beating class. At that point, there is no connection between the int in the Beating class and the DependencyProperty.

The simplest option is probably to reverse the connection, and use binding to move the values around when they change:
C#
internal sealed class Beating : INotifyPropertyChanged
{
    private readonly Timer? _timer;
    private int _value;
    private bool _direction;
    
    public int Value
    {
        get { return _value; }
        set
        {
            if (value != _value)
            {
                _value = value;
                OnPropertyChanged();
            }
        }
    }
    
    public int Increment { get; set; }
    public int MinValue { get; set; }
    public int MaxValue { get; set; }
    public string BeatName { get; }
    
    public double Speed
    {
        get { return _timer.Interval; }
        set { _timer.Interval = value; }
    }
    
    public event PropertyChangedEventHandler? PropertyChanged;
    
    private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    
    public Beating(int initialValue, int increment, int minValue, int maxValue, string beatName, double speed)
    {
        _value = initialValue;
        Increment = increment;
        MinValue = minValue;
        MaxValue = maxValue;
        BeatName = beatName;
        
        _timer = new Timer
        {
            Interval = speed,
            AutoReset = true,
            Enabled = true,
        };
        
        _timer.Elapsed += OnTimedEvent;
    }

    public void StartTimer()
    {
        _timer.Start();
    }

    public void StopTimer()
    {
        _timer.Stop();
    }
    
    private void OnTimedEvent(Object source, ElapsedEventArgs e)
    {
        if (!_direction)
        {
            Value -= Increment;
            if (Value < MinValue)
                _direction = true;
        }
        else
        {
            Value += Increment;
            if (Value > MaxValue)
                _direction = false;
        }
    }
}
C#
public partial class WaitTicker_Control : UserControl
{
    private Beating _timer1;
    private Beating _timer2;
    private Beating _timer3;
    
    private Beating CreateBeating(string beatName, DependencyProperty valueProperty, Border pulse)
    {
        Beating result = new Beating((int)GetValue(valueProperty), PulseIncrementValue, PulseMinValue, PulseMaxValue, beatName, PulseSpeedValue);
        
        // Push changes to the control's properties down to the Beating instance:
        SetBinding(PulseIncrementValueProperty, new Binding(nameof(Beating.Increment)) { Source = result, Mode = BindingMode.OneWayToSource });
        SetBinding(PulseMinValueProperty, new Binding(nameof(Beating.MinValue)) { Source = result, Mode = BindingMode.OneWayToSource });
        SetBinding(PulseMaxValueProperty, new Binding(nameof(Beating.MaxValue)) { Source = result, Mode = BindingMode.OneWayToSource });
        SetBinding(PulseSpeedValueProperty, new Binding(nameof(Beating.Speed)) { Source = result, Mode = BindingMode.OneWayToSource });
        
        // Bind the border's height to the Beating's value:
        pulse.SetBinding(FrameworkElement.HeightProperty, new Binding(nameof(Beating.Value)) { Source = result, Mode = BindingMode.OneWay });
        
        return result;
    }
    
    public WaitTicker_Control()
    {
        InitializeComponent();
        _timer1 = CreateBeating("Pulse1", PulseCurrentValue1Property, Pulse1);
        _timer2 = CreateBeating("Pulse2", PulseCurrentValue2Property, Pulse2);
        _timer3 = CreateBeating("Pulse3", PulseCurrentValue3Property, Pulse3);
    }




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Marc Jeeves2-Sep-22 4:11
Marc Jeeves2-Sep-22 4:11 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Richard MacCutchan3-Sep-22 21:01
mveRichard MacCutchan3-Sep-22 21:01 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
mjeeves3-Sep-22 8:58
mjeeves3-Sep-22 8:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.