1

次のことを行うための簡単なハックはありますか?

<Binding RelativeSource="{RelativeSource AncestorType=UserControl OR Window}" Path="Tag" />

最上位の親の Tag プロパティ (UserControl または Window のいずれか) にバインドしたいだけです。ただし、現在のコントロールから親までの距離は任意であるため、使用できないことに注意してくださいAncestorLevel

4

2 に答える 2

3

それがあなたが望むハックならまあ:)

public partial class MainWindow : ITopLevel
{
    public MainWindow()
    {
        InitializeComponent();

        Tag = "I'm at the top";
    }
}

public interface ITopLevel
{
    // optionally specify Tag in the interface, it will work either way
    object Tag { get; set; }
}

<Grid>
    <Button Content="{Binding Path=Tag, RelativeSource={RelativeSource 
            FindAncestor, AncestorType={x:Type Demo:ITopLevel}}}"/>
</Grid>
于 2013-03-10T20:43:41.587 に答える