I have a user control that contains only an image. This image is computed in execution time. In behind there is a WritableBitMap where I do my ploting. Then the image.source is set to this WritableBitMap.
So my user control looks like:
public partial class ColorBrainMap : UserControl
{
//... some stuff
//I load the base image from the resources
BitmapImage tempImg = new BitmapImage();
tempImg.BeginInit();
tempImg.UriSource = new Uri("pack://application:,,,/ColorBrainMap;component/imgs/brain.png");
tempImg.EndInit();
//I copy the image into a WritableBitMap for convenience
WriteableBitmap baseImage = new WriteableBitmap(tempImg);
//I do some plotting over the base image
//and set the final result as a source for the image
image.Source = baseImage;
}
In the other side my xaml is extremelly simple:
<Grid>
<Image HorizontalAlignment="Stretch" Name="image" Stretch="Fill" VerticalAlignment="Stretch"/>
</Grid>
The I create my new project. I add the component as a reference and drop a new instance into my xaml so it looks like that:
<Window x:Class bla bla
Height="396" Width="541"
xmlns:my="clr-namespace:ColorBrainMapTOOL;assembly=ColorBrainMap">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300*" />
<ColumnDefinition Width="219*" />
</Grid.ColumnDefinitions>
<my:ColorBrainMap HorizontalAlignment="Stretch" Name="brainMap" VerticalAlignment="Stretch" />
<!-- some other components in the other column of the grid-->
</Grid>
</Window>
The whole thing works nicelly until I try to resize it. The control itself resizes (I tested it adding some background and border and the whole thing moves nicelly) but not the image. The image recalculates the plot on demand and works nice but it get stuck to it initial size.
Any clue of how to do it without resizing the internal images and recalculating the plots and all that work again ??
I think you can use a
ViewBoxand set your Image or theColorBrainMapto be its Child;