代码背后的UWP按钮边框图像刷图像?

时间:2017-11-29 09:21:19

标签: uwp border imagebutton imagebrush

我在XAML中有一个带图像边框的按钮:

        <Button Content="Button" HorizontalAlignment="Left" Height="128" Margin="405,16,0,0" Grid.Row="1" VerticalAlignment="Top" Width="295" Foreground="Red">
        <Button.BorderBrush>
            <ImageBrush Stretch="Fill" ImageSource="Assets/myGraphic.png"/>
        </Button.BorderBrush>
    </Button>

代码背后的代码是什么?

我的代码:

Button button = new Button()
                    {
                        FontWeight = FontWeights.Bold,
                        FontSize = 12,
                        --> BorderBrush = ?? // new Imagesource("Assets/myGraphic.png")
                        // Foreground = new SolidColorBrush(Colors.Red),
                        VerticalContentAlignment = VerticalAlignment.Bottom,
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        Content = "my new Button",
                        Tag = i
                    };

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

将ImageBrush分配给BorderBrush属性:

var button = new Button
{
    BorderBrush = new ImageBrush(new BitmapImage(new Uri(...)))
    ...
};