Category Archives: Snippets

Invoking WPF Control for Thread-Safe Call

if(!timerBox.CheckAccess()) {                   Dispatcher.Invoke(                                                                             DispatcherPriority.Send,(Action)delegate {    //********Your Code goes Here*********                   });                                                                                                                                                                         } ////////////////////////////////////////////////////////// //********* this mathod does not need new Thread ******** Main_grid.Dispatcher.Invoke(                                               DispatcherPriority.Background, new Action(() =>{  Main_grid.Children.Add(el);                                                                                                            }));   Advertisements

Posted in Snippets, Wpf | Leave a comment

How to create shaped or irregular window in WPF

How to create shaped or irregular window in WPF

Posted in Snippets, Wpf | Leave a comment

Get Cursor Position on Wpf

    [DllImport(“user32.dll”)]     [return: MarshalAs(UnmanagedType.Bool)]     static extern bool GetCursorPos(out POINT lpPoint);     [StructLayout(LayoutKind.Sequential)]     public struct POINT {       public int X;       public int Y;       public POINT(int x, int y) {         this.X = x;         this.Y = y;       }     }     POINT p;       if(GetCursorPos(out p) && myEllipse … Continue reading

Posted in Snippets, Wpf | Leave a comment

Ctrl key press condition in WPF MouseLeftButtonDown event-handler

private void ellipse1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { //some code } }

Posted in Snippets, Wpf | Leave a comment

how to change Ellipse fill Color at runtime

ellipse1.Fill = new SolidColorBrush(Color.FromRgb(1,1,1));

Posted in Snippets, Wpf | Leave a comment