ViewDefinition Bindings not working for 1st view

16 posts, 0 answers
  1. Philipp
    Philipp avatar
    17 posts
    Member since:
    Jun 2011

    Posted 04 Dec 2011 Link to this post

    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
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 07 Dec 2011 Link to this post

    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Philipp
    Philipp avatar
    17 posts
    Member since:
    Jun 2011

    Posted 11 Dec 2011 Link to this post

    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
  5. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 12 Dec 2011 Link to this post

    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 >>

  6. Shawn Shaddock
    Shawn Shaddock avatar
    25 posts
    Member since:
    Jun 2009

    Posted 24 Feb 2012 Link to this post

    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')
  7. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 27 Feb 2012 Link to this post

    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 >>
  8. Shawn Shaddock
    Shawn Shaddock avatar
    25 posts
    Member since:
    Jun 2009

    Posted 27 Feb 2012 Link to this post

    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
  9. Philipp
    Philipp avatar
    17 posts
    Member since:
    Jun 2011

    Posted 27 Feb 2012 Link to this post

    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.
  10. Shawn Shaddock
    Shawn Shaddock avatar
    25 posts
    Member since:
    Jun 2009

    Posted 29 Feb 2012 Link to this post

    I am trying to produce a demo to try and convince management to move to telerik controls and this issue is holding me up.
  11. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 01 Mar 2012 Link to this post

    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 >>
  12. Shawn Shaddock
    Shawn Shaddock avatar
    25 posts
    Member since:
    Jun 2009

    Posted 01 Mar 2012 Link to this post

    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
  13. Shawn Shaddock
    Shawn Shaddock avatar
    25 posts
    Member since:
    Jun 2009

    Posted 02 Mar 2012 Link to this post

    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.
  14. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 06 Mar 2012 Link to this post

    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 >>
  15. Shawn Shaddock
    Shawn Shaddock avatar
    25 posts
    Member since:
    Jun 2009

    Posted 06 Mar 2012 Link to this post

    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')
  16. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 09 Mar 2012 Link to this post

    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 >>
  17. CHRISTOPH
    CHRISTOPH avatar
    3 posts
    Member since:
    Aug 2012

    Posted 09 Nov Link to this post

    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

Back to Top
UI for WPF is Visual Studio 2017 Ready