There is a Test class and there is a collection in which the processing progress is to be monitored.

Did as below, but every now and then the exception appears "The default value type does not match the property type".

Code-behind:

public static DependencyProperty ProgressProperty = DependencyProperty.Register("Progress", typeof(double), typeof(Test), new FrameworkPropertyMetadata(FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender))); public static DependencyProperty MaxProperty = DependencyProperty.Register("Max", typeof(double), typeof(Test), new FrameworkPropertyMetadata(FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender))); public static DependencyProperty MinProperty = DependencyProperty.Register("Min", typeof(double), typeof(Test), new FrameworkPropertyMetadata(FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender))); 

Xaml markup looks like this:

 <ProgressBar x:Name="pbMain" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Height="20" Maximum="{Binding Source={x:Static local:Test.MaxProperty}}" Value="{Binding Source={x:Static local:Test.ProgressProperty}, Mode=OneWay}" Minimum="{Binding Source={x:Static local:Test.MinProperty}}" /> 

Do I understand correctly that binding should be done through dependency properties?

    1 answer 1

    Strange you declare Dependency Property, without a getter and setter.

    Well, you need to be tied to Max , and not to MaxProperty .

    If the Test class is your DataContext , try this:

     Maximum="{Binding Max}" 

    If the Test class is your control that contains the XAML markup (for example, a window), do this:

     Maximum="{Binding Max, RelativeSource={RelativeSource Self}}"