更改XAML中的Binding值

| 我需要在XAML中进行一些复杂的绑定。我有
DependencyProperty
typeof(double)
;我们将其命名为
SomeProperty
。在控件的XAML代码中的某个位置,我需要使用整个the2ѭ值,仅在一半处,在
SomeProperty/3
处使用,依此类推。 我该怎么做:
<SomeControl Value=\"{Binding ElementName=MyControl, Path=SomeProperty} / 3\"/>
:) 期待。
已邀请:
用除法
ValueConverter
public class DivisionConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        int divideBy = int.Parse(parameter as string);
        double input = (double)value;
        return input / divideBy;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}
<!-- Created as resource -->
<local:DivisionConverter x:Key=\"DivisionConverter\"/>

<!-- Usage Example -->
<TextBlock Text=\"{Binding SomeProperty, Converter={StaticResource DivisionConverter}, ConverterParameter=1}\"/>
<TextBlock Text=\"{Binding SomeProperty, Converter={StaticResource DivisionConverter}, ConverterParameter=2}\"/>
<TextBlock Text=\"{Binding SomeProperty, Converter={StaticResource DivisionConverter}, ConverterParameter=3}\"/>

要回复问题请先登录注册