Cannot find Datacontext (Viewdefinitions)

2 posts, 0 answers
  1. Vikas
    Vikas avatar
    64 posts
    Member since:
    May 2014

    Posted 25 Oct 2014 Link to this post

    I am having problem in binding to the Datacontext at viewdefinition level, It works if i create my viewmodel in xaml and set the DataContext of the grid using staticresource, but if i set the datacontext to the window in code behind it does not work

                    <schedule:DayViewDefinition GroupFilter="{Binding GroupFilter2}"/>
                    <schedule:WeekViewDefinition GroupFilter="{Binding GroupFilter2}"/>
                    <schedule:MonthViewDefinition GroupFilter="{Binding GroupFilter2}"/>

    ----------- this does not work, does no bind to Group Filter -----------------
    public MainWindow()
                this.DataContext = new ViewModel();

    ----------- this works -------------------

            <local:ViewModel x:Key="ViewModel" AppointmentsSource="/Schedule;component/Appointments.xaml" />
    <Grid x:Name="mainGrid" DataContext="{StaticResource ViewModel"> 
  2. Kalin
    Kalin avatar
    1283 posts

    Posted 27 Oct 2014 Link to this post

    Hi Vikas,

    In order to get the binding working correctly you would need to either set the DataContext in XAML or above the InitializeComponent in the constructor of the MainWindow:

    public MainWindow()
        this.DataContext = new ViewModel();

    Hope this helps.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top