I have a simple WPF MVVM application that consist of a `MainWindow` and two UserControl (`Login`, `Register`) and Database Table `Users`. I want to bind the user control to main window like, if in my sql table data already exist then `Login` user control will be displayed else `Register` user control.
['https://Stackoverflow.com/questions/29227143', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4701699/']
If you look at my answer to the [WPF MVVM navigate views](https://stackoverflow.com/questions/19654295/wpf-mvvm-navigate-views/19654812#19654812) question, you'll find a way to display different views in a single place. The answer to your question is for you to implement a similar setup in which you can display either your `Login` view or your `Register` view:

```
public BaseViewModel ViewModel { get; set; }

```

...

```
<DataTemplate DataType="{x:Type ViewModels:LoginViewModel}">
    <Views:LoginView />
</DataTemplate>
<DataTemplate DataType="{x:Type ViewModels:RegisterViewModel}">
    <Views:RegisterView />
</DataTemplate>

```

When your main view model loads, you simply need to check whether you have any data in the database for the current user and then choose to display the relevant view... perhaps something like this:

```
ViewModel = IsUsernameRegistered(username) ? new LoginView() : new RegisterView();

```
I got my answer as
Write the below method in **App.xaml.cs** and delete **StartupUri=""** from **App.xaml**

```
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        var con = new SqlConnection
        {
            ConnectionString = "Data Source=localhost;Initial Catalog=demo;User ID=sa;Password=mypassword;"
        };
        con.Open();
        const string chkadmin = "select COUNT(*) from dbo.Registrations";
        var command = new SqlCommand(chkadmin, con);
        int count = Convert.ToInt32(command.ExecuteScalar());
        if (count == 0)
        {
            var reg = new AdminUser(); //this is the Registration window class
            this.MainWindow = reg;
            reg.Show();
        }
        else
        {
            var win = new Home(); //this is the Home window class
            this.MainWindow = win;
            win.Show();
        }
    }

```