Search code examples
c#wpf2-way-object-databinding

Data-Binding Property Value "Flickers"


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


Solution

  • 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*