画像のみを含むユーザー コントロールがあります。このイメージは実行時に計算されます。背後には、プロットを行う WritableBitMap があります。次に、image.source がこの WritableBitMap に設定されます。したがって、私のユーザーコントロールは次のようになります。
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;
}
反対側では、私の xaml は非常に単純です。
<Grid>
<Image HorizontalAlignment="Stretch" Name="image" Stretch="Fill" VerticalAlignment="Stretch"/>
</Grid>
新しいプロジェクトを作成します。コンポーネントを参照として追加し、新しいインスタンスを xaml にドロップすると、次のようになります。
<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>
サイズを変更しようとするまで、全体がうまく機能します。コントロール自体のサイズは変更されますが (背景と境界線を追加してテストすると、全体がうまく動きます)、画像は変更されません。画像はオンデマンドでプロットを再計算し、うまく機能しますが、初期サイズに固執します。
内部画像のサイズを変更したり、プロットを再計算したり、すべてが再び機能することなく、それを行う方法の手がかりはありますか??