我想在我的XAML中绑定几个不同的属性:如何绑定到RelativeSource Self?
<Label Content="{Binding Description}"
Visibility="{Binding Path=DescriptionVisibility,
ElementName=_UserInputOutput}"
FontSize="{Binding Path=FontSizeValue, ElementName=_UserInputOutput}"
HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" />
你会发现我在这里用了两个不同的结合技术。使用元素名称的工作,另一个不工作。这里是后面的代码:
public string Description
{
get { return (string)GetValue(DescriptionProperty); }
set { SetValue(DescriptionProperty, value); }
}
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(string), typeof(UserControl),
new UIPropertyMetadata(""));
每个绑定具有不同的名称,但它们大部分都是这样的。 我希望我的绑定能够与合作:
{Binding Description}
相反的:
{Binding Path=Description, ElementName=_UserInputOutput}
似乎只用于的ElementName时要工作。我需要导出/导入这个XAML,所以我不能有一个ElementName或导入不起作用。
我想这将是最好的:
{Binding Path=Description, RelativeSource={RelativeSource Self}}
这没有奏效。
任何想法??谢谢!
[本文](http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/debugging-data-bindings-in-a-wpf-or-silverlight-application.aspx)可能会感兴趣。 – 2012-08-16 23:01:50