【问题标题】:How to remove the border of a Button in code?如何在代码中删除按钮的边框?
【发布时间】:2011-06-23 09:19:15
【问题描述】:

我正在开发一个 windows phone 7 应用程序。我是 Windows Phone 7 应用程序的新手。在我的应用程序中,我动态创建了一个按钮控件,并将背景图像添加到按钮控件中,如下所示。

Button AlphabetButton = new Button();
                AlphabetButton.Content = vAlphabet;
                ImageBrush brush = new ImageBrush();
                brush.ImageSource = new BitmapImage(new Uri("button_off.png", UriKind.Relative));
                //brush.Stretch = Stretch.None;
                AlphabetButton.Background = brush;
                AlphabetButton.BorderBrush = new SolidColorBrush(Colors.Gray);

                AlphabetButton.Margin = new Thickness(-12, -27, 0, 0);
                AlphabetButton.Width = 80;
                AlphabetButton.Height = 80;     

我想删除按钮控件的边框,因为使用该边框时,图像不会按要求显示。这个怎么做?我们可以使用按钮控件的BorderThickness 属性来做到这一点,还是有其他方法?您能否提供我可以解决上述问题的任何代码或链接?如果我做错了什么,请指导我。

【问题讨论】:

    标签: silverlight button windows-phone-7 background-image borderless


    【解决方案1】:

    我认为 Button.StrokeTHickness 是调整边框的正确属性。

    【讨论】:

    • Silverlight for Windows Phone 7 按钮中没有此类属性。
    【解决方案2】:

    最简单的方法是将 BorderThickness 设置为 0,例如:

                Button alphabetButton = new Button();
                alphabetButton.BorderThickness = new Thickness(0.0);
    

    另一个选项可能是将 BorderBrush 设置为透明或更改按钮的整个样式,尤其是其 ControlTemplate。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-12
      • 2015-09-01
      • 1970-01-01
      • 2012-07-14
      • 2022-11-26
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多