Problem with DataContext.

2 posts, 0 answers
  1. Sergiy
    Sergiy avatar
    38 posts
    Member since:
    Jan 2012

    Posted 14 Sep 2012 Link to this post

    Hi, I try binding command, but it doesn't work.

    private readonly EmployeeContextViewModel _ucvm;
    public MainWindow() // RadWindow
    {
        InitializeComponent();
         _ucvm = new EmployeeContextViewModel();
         DataContext = _ucvm;  // <<<<<<<<<
    }

    xaml:

    <t:RadButton Content="Exit"
            x:Name="LoginButton"
          Command="{Binding LogoutCommand}"/>

    But it works when I indicates the specific component:

    public MainWindow()
    {
        InitializeComponent();
         _ucvm = new EmployeeContextViewModel();
        LoginButton.DataContext = _ucvm; // <<<<<<<<<<<<<< 
    }
    everything works fine.
    Why doesnot work in the first case and how to fix it?

  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 19 Sep 2012 Link to this post

    Hello Sergiy,

    The command bindings seem to be correct but there may be something causing the issue in the ViewModel.

    Can you send us a runnable project that recreates the issue in order for us to be able to assist you accordingly.

    Looking forward to your response.

    Regards,
    Vladi
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top