Change Border Properties in WPF in VB.NET

This article shows how to change the Background color of a Border element.
  • 4758
This article shows how to change the Background color of a Border element.


The following example places a Button element near the center of a Canvas. The Canvas is nested within a Border element in order to display a border around the element. When you click the Buttonelement, the Brush color of the Border element changes to LightSteelBlue. The click event also adds a string of text in a TextBlock to the Canvas (which indicates that the event occurred) and updates the text content of the Button element.

  Title="Change Border Programmatically">
    <Border Name="root"
            <Button Name="btn" Canvas.Top="40" Canvas.Left="40" Background="LightSkyBlue"Height="35" Click="ChangeBG">Click Me to change the Background Color</Button>
            <TextBlock Canvas.Top="130" Canvas.Left="40" Name="Text1">Waiting for Click!</TextBlock>

The following code-behind file handles the ChangeBG method.

Private Sub ChangeBG(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs)
    root.Background = System.Windows.Media.Brushes.LightSteelBlue
    btn.Content = "Clicked!"
    Text1.Text = "The background is now LightSteelBlue"
End Sub


More Articles

© 2020 DotNetHeaven. All rights reserved.