【问题标题】:WPF TextBox Height Equals Parent Height minus 50 pixels?WPF文本框高度等于父高度减去50像素?
【发布时间】:2010-12-16 21:52:43
【问题描述】:

我成功地让 TextBox 使用父边框高度调整大小,但我需要 TextBox 实际上的高度比父边框小 50 像素。

任何想法如何实现这一目标?

我使用的代码是

<Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
     <TextBox x:Name="txtActivityNotes" HorizontalAlignment="Stretch" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}, Path=ActualHeight}" AcceptsReturn="True" VerticalContentAlignment="Top" TextWrapping="WrapWithOverflow" VerticalScrollBarVisibility="Auto" />
</Border>

【问题讨论】:

    标签: wpf textbox height


    【解决方案1】:

    在绑定上使用转换器如何将高度减去 50

    heres an example of using a converter

    【讨论】:

    • 嗨,Aran,我曾考虑使用转换器,但将值调整 50 似乎有点矫枉过正!我在其他地方使用转换器来提高可见性等,但我希望有一个更简单的解决方案,如果存在的话......
    • 转换器是 wpf 中的正常方式。是的,保证金在这种特殊情况下会起作用,但转换器也是有效的灵魂。并且在很多情况下是唯一的方式。
    【解决方案2】:

    你不能把下边距设置为 50 吗?

    <TextBox Margin="0,0,0,50" />
    

    【讨论】:

      【解决方案3】:

      我已经尝试过,它有效。 在 xaml 中的文本框中添加以下内容:

      ------
      VerticalAlignment="Stretch" 
      HorizontalAlignment="Stretch" 
      Height="{Binding RelativeSource={RelativeSource FindAncestor, *AncestorType*={x:Type *Grid*}}, Path=ActualHeight}"
      ------
      

      这里,AncestorType 是包含文本框的容器类型。就我而言,它是“网格”。 并添加边距,例如,

        Margin="0,0,0,50"
      

      与下方的边界保持距离。

      ============

      抱歉,我在同一页面上发布了。!

      【讨论】:

        猜你喜欢
        • 2017-04-29
        • 2016-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-30
        • 1970-01-01
        • 2018-03-02
        相关资源
        最近更新 更多