Thursday, April 12, 2007

WPF: Media Player

MediaPlayer player;
Uri uri = new Uri("pack://siteoforigin:,,,/music.mp3");
player = new MediaPlayer();
player.Open(uri);
player.Play();

Wednesday, April 11, 2007

WPF: setting cursor

eg:
void Page1_MouseMove(object sender, MouseEventArgs e)
{
e.MouseDevice.SetCursor(Cursors.Hand); //-- hand cursor
e.MouseDevice.SetCursor(Cursors.None); //-- none, invisible
}

WPF: Image Drawing

XAML:
<Image Name="image1" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" Height="200" Width="200" />

C#:
DrawingGroup group = new DrawingGroup();
DrawingImage di = new DrawingImage(group);
//-- create clipping bound for drawing group
RectangleGeometry myRectangleGeometry = new RectangleGeometry();
myRectangleGeometry.Rect = new Rect(0,0,250,250);
group.ClipGeometry = myRectangleGeometry;
image1.Source = di;

//-- load image source (refer to prev post)
ImageSource img2 = ...

//-- to draw something
using (DrawingContext dc = group.Open())
{
dc.DrawImage(img2, new Rect(x, y, w, h));
//-- and other stuff
}