1

Problem:

When I change the value of "LuxVoltage" in the GUI via the Slider or the NumericUpDown the Value jumpes from "default value" (in this case 0) to the "actual value". Assuming I set the Value to 1000 and print out every set this is what the output looks like (it kind of "flickers"):

Output:

0
1000
0
1000
[repeat]

XAML: (Using MahApps.Metro "NumericUpDown")

<metro:NumericUpDown
    Value="{Binding LuxVoltage, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
    Minimum="0"
    Maximum="65535"
    />
<Slider
    Value="{Binding LuxVoltage, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
     Minimum="0"
     Maximum="65535"
    />

C#: (Using Prisms "BindableBase")

private ushort _luxVoltage = 0;
public ushort LuxVoltage
{
    get { return _luxVoltage; }
    set { SetProperty(ref _luxVoltage, value); }
}

Requirement:

I need to manipulate the same value from two controls. The "slider" to simply change the value fast, and the "NumericUpDown" tho provide precision

4 Answers4

0

I don't know why you have a problem with flickering, but when I've had two GUI things chained from one value in the past I've always gone for the approach (using your case) of binding the NumericUpDown to the property in your viewmodel, and then binding the Slider to the NumericUpDown property. It might work for you.

LordWilmore
  • 2,829
  • 2
  • 25
  • 30
0

The type of the Value of Slider is double. As you are binding to a ushort this causes multiple updates even though the slider does not move. Which then might cause additional changes fired from the other control, try adding this to the Slider binding so it when you drag the slider it will only increment it by the tick frequency which is defaulted to "1.0".

IsSnapToTickEnabled="True"
Janne Matikainen
  • 5,061
  • 15
  • 21
0

seems like that the actual problem lives somewhere else in my codebase.

- Binding from 2 Controls to one Property schould just work fine.

- Or consider binding one of the Controls to the value of the other, whose value is bound to the Property*

0

Try checking the incoming value on the setter for a meaningful change before you call SetProperty.

private ushort _luxVoltage = 0;
public ushort LuxVoltage
{
    get { return _luxVoltage; }
    set 
    {
        if (_luxVoltage != value)
        { 
            SetProperty(ref _luxVoltage, value); 
        }
    }
}
Tim Oehler
  • 109
  • 3