多重绑定依赖问题 属性
issue with multibinding dependency property
我正在研究自定义控件。
我有三个依赖项 属性,如下所述。
现在根据用户提供的控件高度、宽度和范围,我必须计算一个值和
在自定义控件中显示。
我正在尝试使用多重绑定,我可以在其中绑定所有这三个值,我的多值转换器将对此进行一些计算
returns 给我适当的值。
问题是我不知道将样式中的这个值绑定为多值转换器绑定。
依赖属性:
public static readonly DependencyProperty ControlHeightProperty =
DependencyProperty.Register("ControlHeight", typeof(double), typeof
(TestControl), new PropertyMetadata(150D));
public double ControlHeight
{
get { return (double)GetValue(ControlHeightProperty); }
set { SetValue(ControlHeightProperty, value); }
}
public static readonly DependencyProperty ControlWidthProperty =
DependencyProperty.Register("ControlWidth", typeof (double), typeof
(TestControl), new PropertyMetadata(default(double)));
public double ControlWidth
{
get { return (double) GetValue(ControlWidthProperty); }
set { SetValue(ControlWidthProperty, value); }
}
public static readonly DependencyProperty RangeProperty =
DependencyProperty.Register("Range", typeof (double), typeof
(TestControl), new PropertyMetadata(default(double)));
public double Range
{
get { return (double) GetValue(RangeProperty); }
set { SetValue(RangeProperty, value); }
}
样式(我没有写绑定):如果属性可用相同的样式,我可以做
使用 ElementName 绑定。但在这种情况下,atlease 可能是高度和宽度是可能的。但是 Range 是直接依赖 属性
我必须以我的风格绑定(我的意思是我无法进行 ElementName 绑定)
<TextBlock Grid.Row="1">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource
CalculateConverter}">
<Binding Path=""></Binding>
<Binding Path=""></Binding>
<Binding Path=""></Binding>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
有人可以帮助我吗?
感谢和问候,
您可以使用 RelativeSource
。
<Binding Path="Range" RelativeSource="{RelativeSource AncestorType=UserControl, Mode=FindAncestor}"></Binding>
我正在研究自定义控件。
我有三个依赖项 属性,如下所述。 现在根据用户提供的控件高度、宽度和范围,我必须计算一个值和 在自定义控件中显示。
我正在尝试使用多重绑定,我可以在其中绑定所有这三个值,我的多值转换器将对此进行一些计算 returns 给我适当的值。
问题是我不知道将样式中的这个值绑定为多值转换器绑定。
依赖属性:
public static readonly DependencyProperty ControlHeightProperty =
DependencyProperty.Register("ControlHeight", typeof(double), typeof
(TestControl), new PropertyMetadata(150D));
public double ControlHeight
{
get { return (double)GetValue(ControlHeightProperty); }
set { SetValue(ControlHeightProperty, value); }
}
public static readonly DependencyProperty ControlWidthProperty =
DependencyProperty.Register("ControlWidth", typeof (double), typeof
(TestControl), new PropertyMetadata(default(double)));
public double ControlWidth
{
get { return (double) GetValue(ControlWidthProperty); }
set { SetValue(ControlWidthProperty, value); }
}
public static readonly DependencyProperty RangeProperty =
DependencyProperty.Register("Range", typeof (double), typeof
(TestControl), new PropertyMetadata(default(double)));
public double Range
{
get { return (double) GetValue(RangeProperty); }
set { SetValue(RangeProperty, value); }
}
样式(我没有写绑定):如果属性可用相同的样式,我可以做 使用 ElementName 绑定。但在这种情况下,atlease 可能是高度和宽度是可能的。但是 Range 是直接依赖 属性 我必须以我的风格绑定(我的意思是我无法进行 ElementName 绑定)
<TextBlock Grid.Row="1">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource
CalculateConverter}">
<Binding Path=""></Binding>
<Binding Path=""></Binding>
<Binding Path=""></Binding>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
有人可以帮助我吗?
感谢和问候,
您可以使用 RelativeSource
。
<Binding Path="Range" RelativeSource="{RelativeSource AncestorType=UserControl, Mode=FindAncestor}"></Binding>