我想在我的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