Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF : Adding Border to an image programmatically

Tags:

c#

wpf

I want to add a style to the the image programmatically. Here is my code

<UserControl.Resources>
       <Style x:Name="BranchPages" x:Key="BranchPages">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Border BorderThickness="2" BorderBrush="Green">
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
</UserControl.Resources>

and the code behid is as follows

  Style greenbdr = (Style)FindResource("BranchPages");
  page.img.Style = greenbdr;

But Its not working Please help

like image 976
user279244 Avatar asked Feb 24 '10 15:02

user279244


1 Answers

This workaround might help:

Since the Image has no border, place it inside a Border control.

<Border Name="imgBorder" BorderThickness="2" BorderBrush="Transparent">
        <Image Name="img"></Image>
</Border>

Then create logic code against the properties of that Border.

imgBorder.BorderBrush = Brushes.Green; 
like image 138
Jojo Sardez Avatar answered Sep 23 '22 04:09

Jojo Sardez