I am developing a custom image control in WPF.NET 3.5 and Visual Studio 2010.
In WinForms, the PicutreBox control has a SizeMode property that includes a " CenterImage ".
I want my image control to have this ability.
Anyway?
thank
My XAML code:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="768" Width="1024" xmlns:my="http://schemas.sharpsoft.net/xaml" xmlns:my1="clr-namespace:WpfApplication1">
<Grid>
<my1:CustomControl1
x:Name="customControl11"
Width="206"
Height="197"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="18,58,0,0"
Stretch="Uniform"/>
</Grid>
</Window>
My custom code is:
public class CustomControl1 : Image
{
public CustomControl1()
{
Stream ms = new MemoryStream();
Properties.Resources.webcam_background.Save(ms, ImageFormat.Png);
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = ms;
bitmap.EndInit();
Source = bitmap;
}
}
Where "webcam_backgroud" is the PNG image added by the default visual studio resource editor.
source
share