I am not sure if this question has been asked before or not but i am currently in a situation where i bind my control's property to a DependencyProperty
.However, the value returned by the Property
is of type Double
. When setting the binding, how do i subtract 20
or a given value from the property and then bind the control ? Do i need to implement IValueConverter
for this ? I am still studying WPF so any help would be appreciated.
Dependency property
public static readonly DependencyProperty ProgressbarValueDependency = DependencyProperty.Register("PrValue", typeof(double), typeof(LinearProgressBar));
public double PrValue
{
get
{
return System.Convert.ToDouble(GetValue(ProgressbarValueDependency));
}
set
{
SetValue(ProgressbarValueDependency, value);
}
}
Binding to the property
{
MainGrid = GetTemplateChild("MainGrid");
Binding MainGridWidthBinding = new Binding("PrValue")
{
Source = this,
Mode = BindingMode.TwoWay
};
MainGrid.SetBinding(Grid.WidthProperty, MainGridWidthBinding);
}