This is a migrated thread and some comments may be shown as answers.

Cannot find Datacontext (Viewdefinitions)

1 Answer 344 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Vikas
Top achievements
Rank 1
Vikas asked on 25 Oct 2014, 09:32 PM
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:RadScheduleView.ViewDefinitions>
                <schedule:DayViewDefinition GroupFilter="{Binding GroupFilter2}"/>
                <schedule:WeekViewDefinition GroupFilter="{Binding GroupFilter2}"/>
                <schedule:MonthViewDefinition GroupFilter="{Binding GroupFilter2}"/>
            </schedule:RadScheduleView.ViewDefinitions>

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


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

<Window.Resources>
        <local:ViewModel x:Key="ViewModel" AppointmentsSource="/Schedule;component/Appointments.xaml" />
<Grid x:Name="mainGrid" DataContext="{StaticResource ViewModel"> 

1 Answer, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 27 Oct 2014, 09:28 AM
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();
    InitializeComponent();
}

Hope this helps.

Regards,
Kalin
Telerik
 

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.

 
Tags
ScheduleView
Asked by
Vikas
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Share this question
or