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

ViewDefinition Bindings not working for 1st view

15 Answers 421 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Philipp
Top achievements
Rank 1
Philipp asked on 05 Dec 2011, 01:31 AM
I have a ScheduleView with the following setup - the actual time spawn and tick marks are being provided by the view model:

<telerik:RadScheduleView.ViewDefinitions>
    <telerik:TimelineViewDefinition MinorTickLength="{Binding MinorTickLength}" MinTimeRulerExtent="{Binding MinTimeRulerExtent}" DayStartTime="{Binding StartTime, Mode=OneWay}" DayEndTime="{Binding EndTime, Mode=OneWay}"  MajorTickLength="1h" Orientation="Vertical" StretchGroupHeaders="True" StretchAppointments="True" VisibleDays="1"/>
    <telerik:DayViewDefinition      MinorTickLength="{Binding MinorTickLength}" MinTimeRulerExtent="{Binding MinTimeRulerExtent}" DayStartTime="{Binding StartTime, Mode=OneWay}" DayEndTime="{Binding EndTime, Mode=OneWay}"  MajorTickLength="1h" TimerulerMajorTickStringFormat="{}{0:t}" Title="Shift" />
    <telerik:WeekViewDefinition     MinorTickLength="{Binding MinorTickLength}" MinTimeRulerExtent="{Binding MinTimeRulerExtent}" DayStartTime="{Binding StartTime, Mode=OneWay}" DayEndTime="{Binding EndTime, Mode=OneWay}"  MajorTickLength="1h" />
    <telerik:MonthViewDefinition />
</telerik:RadScheduleView.ViewDefinitions>


Now, the problem is that the first view definition doesn't pick up the bindings. The timeline view shows a full day view with the default tick mark lengths. Day view and week view display just fine. Now, if I remove the timeline view definition from my XAML and restart the application, the day view is affected, while the week view still works fine. This looks like a bug to me - and it's a show stopping one.

Thanks for your advice
Philipp

15 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 07 Dec 2011, 04:39 PM
Hi Philipp,

I've tried to reproduce this issue with the provided code but without much success. Could you please open a support ticket and send us a simple project demonstrating the issue there? Thanks in advance.

Greetings,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Philipp
Top achievements
Rank 1
answered on 12 Dec 2011, 02:24 AM
Yana

Thanks for looking into it. The problem still persists, so I'll try to get a repro into you hands by next week.

Cheers,
Philipp
0
Yana
Telerik team
answered on 12 Dec 2011, 08:41 AM
Hi Philipp,

Thanks. We'll check the project as soon as it's ready.

Greetings,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Shawn Shaddock
Top achievements
Rank 1
answered on 24 Feb 2012, 11:06 PM
I'm having a similar issue. I have a single view definition like so

<telerik:RadScheduleView.ViewDefinitions>
    <telerik:DayViewDefinition VisibleDays="{Binding VisibleDays, Mode=OneWay}" MajorTickLength="1h" MinorTickLength="{Binding Interval}" />
</telerik:RadScheduleView.ViewDefinitions>

But when I run it I get the following error in the output window.

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=VisibleDays; DataItem=null; target element is 'DayViewDefinition' (HashCode=48835636); target property is 'VisibleDays' (type 'Int32')
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Interval; DataItem=null; target element is 'DayViewDefinition' (HashCode=48835636); target property is 'MinorTickLength' (type 'ITickProvider')
0
Yana
Telerik team
answered on 27 Feb 2012, 04:37 PM
Hi Shawn,

I've check again and the provided code works without a problem. Please send us more information/sample code which will help us replicate the issue.

All the best,
Yana
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Shawn Shaddock
Top achievements
Rank 1
answered on 27 Feb 2012, 06:59 PM
I started a brand new sample project and tried the simplest solution I could think of to demonstrate the issue.

<Window x:Class="MainWindow"
    xmlns:local="clr-namespace:WpfApplication10"
    Title="MainWindow" Height="350" Width="525">
     
    <Window.DataContext>
        <local:MainViewModel VisibleDays="7" />
    </Window.DataContext>
     
    <Grid>
        <telerik:RadScheduleView>
            <telerik:RadScheduleView.ViewDefinitions>
                <telerik:DayViewDefinition VisibleDays="{Binding VisibleDays}" />
            </telerik:RadScheduleView.ViewDefinitions>
        </telerik:RadScheduleView>
    </Grid>
     
</Window>

Public Class MainViewModel
 
    Public Property VisibleDays As Integer
 
End Class
0
Philipp
Top achievements
Rank 1
answered on 27 Feb 2012, 09:47 PM
Didn't look into it yet, but these are the errors we're getting during startup:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=MinorTickLength; DataItem=null; target element is 'DayViewDefinition' (HashCode=27294362); target property is 'MinorTickLength' (type 'ITickProvider')
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=MinTimeRulerExtent; DataItem=null; target element is 'DayViewDefinition' (HashCode=27294362); target property is 'MinTimeRulerExtent' (type 'Double')
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=StartTime; DataItem=null; target element is 'DayViewDefinition' (HashCode=27294362); target property is 'DayStartTime' (type 'TimeSpan')


Possible that the first element we're declaring doesn't get a DataContext, which breaks all bindings.
0
Shawn Shaddock
Top achievements
Rank 1
answered on 29 Feb 2012, 04:20 PM
I am trying to produce a demo to try and convince management to move to telerik controls and this issue is holding me up.
0
Yana
Telerik team
answered on 01 Mar 2012, 12:36 PM
Hello,

I've attached my test project based on the provided code  - I am still not able to reproduce these errors. Can you tell us, please, which version of the controls you're using?

Regards,
Yana
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Shawn Shaddock
Top achievements
Rank 1
answered on 01 Mar 2012, 07:04 PM
I found out how to reproduce the issue.

It occurs when you don't set the DataContext through XAML.

So instead of doing this
<Window.DataContext>
    <local:MainViewModel />
</Window.DataContext>

Do this in the code behind, and you will see it does not work
Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
    Me.DataContext = New MainViewModel()
End Sub
0
Shawn Shaddock
Top achievements
Rank 1
answered on 02 Mar 2012, 04:56 PM
Another thing to note, although the bindings do work when the DataContext is added through XAML, the errors in the output window are still there.
0
Yana
Telerik team
answered on 06 Mar 2012, 12:08 PM
Hi Shawn,

You are right, we were able to reproduce the error and we will research it.
For now, please change the binding like this:

<telerik:RadScheduleView x:Name="ScheduleView">
    <telerik:RadScheduleView.ViewDefinitions>
        <telerik:DayViewDefinition VisibleDays="{Binding DataContext.VisibleDays, ElementName=ScheduleView}" />
    </telerik:RadScheduleView.ViewDefinitions>
    <telerik:RadScheduleView.AppointmentsSource>
        <telerik:ObservableAppointmentCollection />
    </telerik:RadScheduleView.AppointmentsSource>
</telerik:RadScheduleView>

I've attached the modified project for a reference.

All the best,
Yana
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Shawn Shaddock
Top achievements
Rank 1
answered on 06 Mar 2012, 02:16 PM
Even after changing the bindings I still get these messages in the output window

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=DataContext.VisibleDays; DataItem='RadScheduleView' (Name='Schedule'); target element is 'DayViewDefinition' (HashCode=31132759); target property is 'VisibleDays' (type 'Int32')
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=DataContext.Interval; DataItem='RadScheduleView' (Name='Schedule'); target element is 'DayViewDefinition' (HashCode=31132759); target property is 'MinorTickLength' (type 'ITickProvider')
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=DataContext.DayStartTime; DataItem='RadScheduleView' (Name='Schedule'); target element is 'DayViewDefinition' (HashCode=31132759); target property is 'DayStartTime' (type 'TimeSpan')
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=DataContext.DayEndTime; DataItem='RadScheduleView' (Name='Schedule'); target element is 'DayViewDefinition' (HashCode=31132759); target property is 'DayEndTime' (type 'TimeSpan')
0
Yana
Telerik team
answered on 09 Mar 2012, 10:25 AM
Hi Shawn,

It is normal to see this error (System.Windows.Data Error: 2 : Cannot find governing...) because Binding system waits for the element to Load and then searches the visual tree for the specified element (when element is not loaded there is no point in searching the visual tree. That is why you see the error but it works after the element is loaded).

Regards,
Yana
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Wetzorke
Top achievements
Rank 1
answered on 09 Nov 2016, 04:03 PM

As of UI for WPF R3 2016 (2016.3.1024), the OP's problem still occurs, but can be fixed with http://www.telerik.com/forums/cannot-find-datacontext-(viewdefinitions)#TYnz3UfpVEOxS9zuRgo9sQ

The error messages on the other hand still occur. See also http://www.telerik.com/forums/binding-errors-on-viewdefinitions-titles

Tags
ScheduleView
Asked by
Philipp
Top achievements
Rank 1
Answers by
Yana
Telerik team
Philipp
Top achievements
Rank 1
Shawn Shaddock
Top achievements
Rank 1
Wetzorke
Top achievements
Rank 1
Share this question
or