Reputation: 827
In my windows phone app, I have a rectangular Border
. I want to add image in the center of the border. How to do that using C#
?
Edit This code is not displaying any image. Any idea why ?
Border b = (Border)FindName("border"+nom);
if (move == 1)
{
var bi = new BitmapImage
{
UriSource = new Uri("/Images/smiley1.png", UriKind.Relative)
};
b.Child = new Image { Source = bi };
}
Edit 2
Apparently, correct syntax is UriSource = new Uri("/BoxIt;component/Images/smiley1.png", UriKind.Relative)
This solves the problem :)
Upvotes: 0
Views: 1153
Reputation: 30830
an Image can be adeed to a Border using following code:
// Assume you have a border named Border1
Border1.Child = new Image() { /* ... */ };
Note: I do not recommend this. DataTemplates with Data binding or TemplatedControls should be used when possible.
Upvotes: 0
Reputation: 1761
This is pretty straight forward. You could have done a plain search. Anyways here's the solution you are looking for -
In XAML -
<Border BorderThickness="2,2,2,2" BorderBrush="#FF000000" >
<Image x:Name="imgMainImage" Visibility="Visible" Height="205" Width="180" />
</Border>
Upvotes: 2