System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(100, 100);
using (var g = System.Drawing.Graphics.FromImage(bmp))
IntPtr hdc = g.GetHdc();
//use hdc to draw here
var img = new System.Windows.Controls.Image
Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap
//use img in wpf
Tuesday, December 29, 2009
Monday, September 21, 2009
public class ScrollableDataGrid : DataGrid
MouseWheel += delegate(object sender, MouseWheelEventArgs e)
(OnCreateAutomationPeer() as IScrollProvider).Scroll(ScrollAmount.NoAmount,
e.Delta < 0 ? ScrollAmount.SmallIncrement : ScrollAmount.SmallDecrement);
Thursday, August 27, 2009
All the pixels of the image will be divided between more than one pixel and that makes the images appear blurry.
The solution is to use Math.Round when setting their positions.
Wednesday, August 19, 2009
Thursday, August 13, 2009
How to play a video in a loop in Silverlight?
On numerous websites, a solution using MediaEnded event is offered.
That solution does not work because there's a visible pause before restart.
Here's one with a Marker. It's still not perfect because if you put the time of the marker too close to the end, it may not be reached. For example, 0.01 seconds did not work.
If you make it too far, the video will not be seamless. But at least, it's better than the MediaEnded way of doing it.
MediaElement.MediaOpened += delegate
Time = MediaElement.NaturalDuration.TimeSpan.Subtract(TimeSpan.FromSeconds(0.1))
MediaElement.MarkerReached += delegate
Note that the marker needs to be set after opening the media file.
Wednesday, August 12, 2009
scrollViewer1.MouseWheel += delegate(object sender, MouseWheelEventArgs e)
scrollViewer1.ScrollToVerticalOffset(scrollViewer1.VerticalOffset - e.Delta);
Friday, August 7, 2009
Friday, July 31, 2009
Thursday, July 30, 2009
Go explore other effects too, they're all in the same namespace.
MouseEnter += delegate
Effect = new DropShadowEffect
Color = Colors.Black,
BlurRadius = 13,
ShadowDepth = 3
MouseLeave += delegate
Effect = null;
public class MyClass : UserControl
public static readonly DependencyProperty PaddingTopProperty = DependencyProperty.Register("PaddingTop", typeof(double), typeof(MyClass), new PropertyMetadata(0d, new PropertyChangedCallback(OnPaddingTopPropertyChanged)));
public double PaddingTop
Padding = new Thickness(Padding.Left, value, Padding.Right, Padding.Bottom);
private static void OnPaddingTopPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
(d as MyClass).PaddingTop = (double)e.NewValue;
Wednesday, July 29, 2009
Monday, July 20, 2009
Check the ServiceReferences.ClientConfig file in your Silverlight project. When adding a service reference, this file may have got a remote server name inside XML which is not the same as what you use for connecting to the service. This would create a pseudo cross-domain security problem.
Friday, July 10, 2009
DoubleAnimation dy = new DoubleAnimation
From = from * element.ActualHeight,
To = to * element.ActualHeight,
Duration = TimeSpan.FromSeconds(0.3)
Storyboard.SetTargetProperty(dy, new PropertyPath(FrameworkElement.HeightProperty));
Storyboard sb = new Storyboard();
Thursday, July 9, 2009
Element.RenderTransformOrigin = new Point(0.5, 0.5);
Element.RenderTransform = new RotateTransform();
DoubleAnimation da = new DoubleAnimation
From = 0,
To = 360,
Duration = TimeSpan.FromSeconds(0.5)
Storyboard.SetTargetProperty(da, new PropertyPath(RotateTransform.AngleProperty));
Storyboard sb = new Storyboard();