代码之家  ›  专栏  ›  技术社区  ›  Brad

使用PlacementTarget的WPF组合框下拉列表

  •  0
  • Brad  · 技术社区  · 15 年前

    我有一个 ContentControl 从左到右组成 Button ,分区和 ComboBox . 我想要 组合框 下拉以与控件的左侧对齐,而不是与控件的左侧对齐。 组合框 . 我收到了一个代码中的方法,但我想知道它是否可以在XAML中完成。

    这给了我控件的名称:

    ToolTip="{Binding Path=Name, RelativeSource={RelativeSource FindAncestor, AncestorLevel=2, AncestorType={x:Type Control}}}"
    

    但我想引用控件:

    Placement="Bottom" PlacementTarget="{Binding ElementName=[Fancy-Smancy xaml goes here!]}"
    

    有什么想法吗?

    1 回复  |  直到 11 年前
        1
  •  0
  •   OlivierH    11 年前

    如果指定 AncestorLevel 以及 AncestorType :

    Placement="Bottom" 
    
    PlacementTarget="{Binding RelativeSource={RelativeSource FindAncestor, AncestorLevel=2, AncestorType={x:Type Grid}}}"
    
    推荐文章