Xaml でいくつかの異なるプロパティをバインドしようとしています。
<Label Content="{Binding Description}"
Visibility="{Binding Path=DescriptionVisibility,
ElementName=_UserInputOutput}"
FontSize="{Binding Path=FontSizeValue, ElementName=_UserInputOutput}"
HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" />
ここでは 2 つの異なるバインディング手法を使用していることに気付くでしょう。Element Name を使用するものは機能しますが、他のものは機能しません。コードビハインドは次のとおりです。
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 を次のように操作できるようにしたい:
{Binding Description}
それ以外の:
{Binding Path=Description, ElementName=_UserInputOutput}
ElementName が使用されている場合にのみ機能しているようです。この XAML をエクスポート/インポートする必要があるため、ElementName を取得できないか、インポートが機能しません。
私はこれが最善だと思いました:
{Binding Path=Description, RelativeSource={RelativeSource Self}}
これはうまくいきませんでした。
何か案は??ありがとうございました!