我不确定之前是否有人问过这个问题,但我目前处于将控件的属性绑定到 a 的情况。DependencyProperty但是,返回的值Property是类型Double。设置绑定时,如何20从属性中减去或给定值,然后绑定控件?我需要为此实施IValueConverter吗?我仍在学习 WPF,因此将不胜感激。
依赖属性
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);
}
}
绑定到属性
{
MainGrid = GetTemplateChild("MainGrid");
Binding MainGridWidthBinding = new Binding("PrValue")
{
Source = this,
Mode = BindingMode.TwoWay
};
MainGrid.SetBinding(Grid.WidthProperty, MainGridWidthBinding);
}
SMILET
相关分类