There is a certain structure, for example NotMyStruct . There is no direct access to the structure code. There is a class MyClass , in which there is an instance of this structure called valStruct . In struktru there is a field of a type
uint? Value { get; set; } = null; There is also a UserControl in the bark that is a ListBox with a binding to a DataConext . Objects are added to this ListBox from ObservableCollection via binding. It all works.
Further. Through DataTemplate describe something like this style:
<DataTemplate DataType="{x:Type local:MyClass}"> <Grid> <Slider Value="{Binding valStruct.Value, Converter={StaticResource DoubleToUintConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> </Grid> </DataTemplate> Ps. Converter does not issue errors. Essentially just converts via System.Convert
The problem is that the Value value with and remains null when the slider moves. How to make such a binding?
UPD
[ValueConversion(typeof(double), typeof(uint?))] public class DoubleToUintConverter : MarkupExtension, IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return System.Convert.ToUInt32(value); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return System.Convert.ToDouble(value); } }
valStruct- judging by the name, is it not public? In this case, it will not work correctly. - icebatvalStruct'is an instance of theNotMyStructstructure, It can be quietly public. The problem is thatNotMyStructsealed structure.OnPropertyChanged()implementingOnPropertyChanged()inside is not possible, but I don’t know how to do something else. - BwehaaFoxvalStruct.Valueinto a separate MyClass with PropertyChanged support and do all operations with Value through it? - icebat