Image控件的寫法
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Name="img" />
</Grid>
通過System.Windows.Controls.Control.ManipulationStarted事件來進行調用這這個方法覆寫了System.Windows.UIElement.OnManipulationStarted(System.Windows.Input.ManipulationStartedEventArgs)。
加載網絡的圖檔資源
protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
{
Uri uri = new Uri("http://www.website.com/p_w_picpath/a.jpg");
BitmapImage bmp = new BitmapImage(uri);
img.Source = bmp;
args.Complete();
args.Handled = true;
base.OnManipulationStarted(args);
}
加載本地的圖檔資源
Uri uri = new Uri("../Images/Hello.png", UriKind.Relative);
StreamResourceInfo resourceInfo = Application.GetResourceStream(uri);
BitmapImage bmp = new BitmapImage();
bmp.SetSource(resourceInfo.Stream);