C
There are plenty of problems in your code.For starters, NotMyStruct - typical model data structure, which, of course, INotifyPropertyChanged♪So you can't catch a change in this structure, but you can't just send a change from UI to it.Then you've got a converter in the wrong direction. He has to convert from uint? Total doubleAnd you have the opposite. We fix the converter:public class NullableUintToDoubleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
return (double)((uint?)value ?? 0);
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
return (uint)(double)value;
}
}
Next. Yours. Slider values between 0 and 1, as not displayed Maximum♪ In rounding, the whole thing is clean zero, so... Binding Recording the value 0 to its properties. To fix it, put it to maximum. uint.MaxValue:<Slider Value="{Binding valStruct.Value,
Converter={StaticResource NullableUintToDoubleConverter},
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Minimum="0" Maximum="4294967295"/>
Then there's a big problem: a mutate structure! Mobile structures are evil. Values do not fail through binding valStruct.ValueAnd that's why.How's the treatment going on? valStruct.Value? First class MyClasswhich DataContextUm, looking for publicity. valStructand it's getting its meaning through the ghetter. Since valStruct There's a structure, You get a copy of the value.! When this copy reads the meaning ValueNo problem: Value I don't know what I'm saying. But when in the same way Binding value Value recorded, but only a copy is modified valStructNot the original!How do you fix that? For example, you can invade this characteristic:public NotMyStruct valStruct { get; set; }
public uint? valStructValueBindable
{
get { return valStruct.Value; }
set { valStruct = new NotMyStruct() { Value = value }; }
}
(Please note that we have re-established our properties on the grid!)Or so:NotMyStruct valStruct;
public uint? valStructValueBindable
{
get { return valStruct.Value; }
set { valStruct.Value = value; }
}
(in this case, you're writing straight to the structure, not to her copy).And your XAML is pretending<Slider Value="{Binding valStructValueBindable,
Converter={StaticResource NullableUintToDoubleConverter},
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Minimum="0" Maximum="4294967295"/>
Voila, it works.