【问题标题】:How to set WPF border.Brush to foreground property of other controls like labels?如何将 WPF 边框设置为其他控件(如标签)的前景属性?
【发布时间】:2014-02-14 02:42:16
【问题描述】:

如何设置 WPF 边框。刷到其他控件(如标签)的前景属性?

Border b = new Border();
b.BorderBrush= ?;

【问题讨论】:

    标签: c# .net wpf silverlight xaml


    【解决方案1】:

    为什么不直接在 XAML 中绑定它:

     <Border BorderBrush="{Binding Path=Foreground, ElementName=txtLabel}"/>
    

    【讨论】:

      【解决方案2】:

      查看类似的问题

      http://www.stackoverflow.com/questions/421581/silverlight-binding-a-child-controls-property-to-a-property-in-a-user-control

      如果这没有帮助,为什么不为你的前景色定义一个静态资源:

       <SolidColorBrush x:Key="ForegroundColour" Color="#FFF2F2F2" />
      

      然后将此前景色绑定到您喜欢的任何控件。

      通过代码,它会是这样的:

        fg = this.Resources["ForegroundColour"] as SolidColorBrush;
              b.BorderBrush= fg;              
      

      【讨论】:

        猜你喜欢
        • 2013-05-23
        • 2011-06-28
        • 1970-01-01
        • 1970-01-01
        • 2011-01-02
        • 2011-02-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多