I’m having a problem dealing with events. Basically the program generate images but with the same event.
private Image MakeImage(string filename)
{
Uri uri = new Uri("ms-appx:///CategoryData/" + filename+".png");
BitmapImage bitmap = new BitmapImage(uri);
Image image = new Image()
{
Height = 100,
Width = 100,
Stretch = Stretch.Uniform,
MaxHeight = 250,
MaxWidth = 250,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Name = filename+"Img",
ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY,
};
image.Source = bitmap;
image.ManipulationDelta += image_ManipulationDelta;
return image;
}
void image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
Image image = sender as Image;
CompositeTransform ct = image.RenderTransform as CompositeTransform;
ct.TranslateX += e.Delta.Translation.X;
ct.TranslateY += e.Delta.Translation.Y;
//throw new NotImplementedException();
}
and exception occurs on the “ct.TranslateX += e.Delta.Translation.X;“.
Object reference not set to an instance of an object.
Check your cast to
CompositeTransform, because probably it’s the wrong type — Resulting inctbeingnull, thus into your exception.EDIT: added an example.
Besides, why not using a
TranslateTransformif all you need is translating the image?