Saturday, October 15, 2016

How to make modal dialog in WPF?

Showing your window using the ShowDialog method:

 // set Owner property
w.Owner = Window.GetWindow(this);

// or
w.Owner = this;

// or
w.Owner = Application.Current.MainWindow;

// or
w.Owner = (Window)PresentationSource.FromVisual(this).RootVisual;

w.ShowDialog();

Note: Don't forget to set the Owner property on the dialog window. Otherwise, the user will get weird behavior when Alt+Tabbing, etc.

Reference:

http://stackoverflow.com/questions/499294/how-do-make-modal-dialog-in-wpf

Wednesday, October 12, 2016

Getting first day of the week in MySql using Week number

Getting first day of the week in MySql using Week number

SELECT
 ADDDATE(CURDATE(), INTERVAL (1 - DAYOFWEEK(CURDATE())) DAY) WeekStart,
 ADDDATE(CURDATE(), INTERVAL (7 - DAYOFWEEK(CURDATE())) DAY) WeekEnd

Reference:

http://stackoverflow.com/questions/3317980/getting-first-day-of-the-week-in-mysql-using-week-no

Thursday, October 6, 2016

How to convert a character in to equivalent System.Windows.Input.Key Enum value?

How to convert a character in to equivalent System.Windows.Input.Key Enum value?

            var c = Convert.ToChar(KeyInterop.VirtualKeyFromKey(key));
            Debug.WriteLine("k: " + key);
            Debug.WriteLine("c: " + c);

Reference:

http://stackoverflow.com/questions/289792/int-to-char-in-c-sharp

Lambda Expressions / statement

            this.MyAC.PreviewKeyDown += new KeyEventHandler(async (a, b) =>
                 this.MyAC.ItemsSource = await ViewModels.MainViewModel.GetItems(((RadAutoCompleteBox)a).SearchText, b.Key)
            );

            this.MyAC.PreviewKeyDown += new KeyEventHandler(async (a, b) =>
            {
                 this.MyAC.ItemsSource = await ViewModels.MainViewModel.GetItems(((RadAutoCompleteBox)a).SearchText, b.Key);
                 this.MyAC.ItemsSource.IsDropDownOpen = true;
            }
            );

            this.GridSearchBox.PreviewKeyDown += new KeyEventHandler(async (object a, KeyEventArgs b) =>
            {
                this.GridSearchBox.ItemsSource = await ViewModels.MainViewModel.GetItems(((ComboBox)a).Text, b.Key);
                this.GridSearchBox.IsDropDownOpen = true;
            }
            );

            w.MyAnswer += (value) =>
            {
                this.MyAnswer = value;
            };

            w.Closed += (object sender2, EventArgs e2) =>
            {
                SerialNumBox1.Text = this.MyAnswer;
            };

    child.Closed += new EventHandler(child_Closed);

    void child_Closed(object sender, EventArgs e)
    {
        // Child window closed
    }

            w.MyMsg2 += value2 => textBox3.Text = value2;

Wednesday, October 5, 2016

WPF: How do I set the Owner Window of a Dialog shown by a UserControl?

w.Owner = this;

w.Owner = Window.GetWindow(this);

To get the top level window your control is in, assuming there is one:

(Window)PresentationSource.FromVisual(this).RootVisual

To get the main window:

Application.Current.MainWindow

Reference:

http://stackoverflow.com/questions/607370/wpf-how-do-i-set-the-owner-window-of-a-dialog-shown-by-a-usercontrol

Tuesday, October 4, 2016

C# - Return variable from child window to parent window in WPF

Create an event in your second window, have the parameters of the event's delegate contain whatever information you want to pass:

public class Popup : Window
{
    public event Action<string> Check;

    public void Foo()
    {
        //fire the event
        if (Check != null)
            Check("hello world");
    }
}

Then the main window can subscribe to that event to do what it wants with the information:

public class Main : Window
{
    private Label label;
    public void Foo()
    {
        Popup popup = new Popup();
        popup.Check += value => label.Content = value;
        popup.ShowDialog();
    }
}

Reference:

http://stackoverflow.com/questions/21607925/c-sharp-return-variable-from-child-window-to-parent-window-in-wpf

Monday, October 3, 2016

Install latest Node.js on CentOS 7

Add Node.js Yum Repository:

# curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -

Install Node.js and NPM:

# yum install nodejs

Check Node.js version:

# node -v

v6.7.0

Check NPM version:

# npm -v

3.10.3

Create Demo Web Server:

# vim demo_srv.js

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Welcome Node.js');
}).listen(3001, "127.0.0.1");

console.log('Server running at http://127.0.0.1:3001/');

Start the web server:

# node --debug demo_server.js

Reference:

https://nodejs.org/en/download/package-manager/#enterprise-linux-and-fedora

http://tecadmin.net/install-latest-nodejs-and-npm-on-centos/