VisiblePeriodStart Not Set

11 posts, 1 answers
  1. Darlene
    Darlene avatar
    13 posts
    Member since:
    Jan 2012

    Posted 26 Mar 2012 Link to this post

    Hello!   Using Q1 2012.

    I'm trying to set default values for the period bindings and am having some difficulty with VisiblePeriodStart.  This guy just doesn't want to get set even though they are in the right order and two-way bound.  Suggestions?

    View:
    <telerik:RadTimeBar Height="150" Margin="40,20,40,40" telerik:StyleManager.Theme="Windows7"
                                PeriodStart="{Binding PeriodStart, Mode=TwoWay}"
                                PeriodEnd="{Binding PeriodEnd, Mode=TwoWay}"
                                VisiblePeriodStart="{Binding VisibleStart, Mode=TwoWay}"
                                VisiblePeriodEnd="{Binding VisibleEnd, Mode=TwoWay}"
                                SelectionStart="{Binding SelectionStart, Mode=TwoWay}"
                                SelectionEnd="{Binding SelectionEnd, Mode=TwoWay}"
                                >
     
                <telerik:RadTimeBar.Intervals>
                    <telerik:YearInterval />
                    <telerik:MonthInterval />
                    <telerik:DayInterval />
                </telerik:RadTimeBar.Intervals>
     
                <telerik:RadAreaSparkline ItemsSource="{Binding TimeBarData}" XValuePath="Date" YValuePath="Total" telerik:StyleManager.Theme="Windows7" AutoRange="False" />
            </telerik:RadTimeBar>

    ViewModel:
    public class ViewModel
        {
            public ObservableCollection<DetailTimeBarModel> TimeBarData { get; private set; }
     
            public DateTime PeriodStart { get; set; }
            public DateTime PeriodEnd { get; set; }
            public DateTime VisibleStart { get; set; }
            public DateTime VisibleEnd { get; set; }
            public DateTime SelectionStart { get; set; }
            public DateTime SelectionEnd { get; set; }
     
            public ViewModel()
            {
                TimeBarData = new ObservableCollection<DetailTimeBarModel>
                                  {
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(-20), Total = 5},
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(-18), Total = 1},
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(-16), Total = 3},
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(-14), Total = 7},
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(-12), Total = 6},
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(-10), Total = 3},
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(-8), Total = 12},
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(-6), Total = 6},
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(-4), Total = 3},
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(-2), Total = 3},
                                      new DetailTimeBarModel {Date = DateTime.Now.AddDays(0), Total = 2}
                                  };
     
                PeriodStart = TimeBarData.Min(x => x.Date);
                PeriodEnd = TimeBarData.Max(x => x.Date);
                VisibleStart = PeriodEnd.AddDays(-10);
                VisibleEnd = PeriodEnd;
                SelectionStart = PeriodEnd.AddDays(-2);
                SelectionEnd = PeriodEnd;
            }
        }
     
        public class DetailTimeBarModel
        {
            public DateTime Date { get; set; }
            public int Total { get; set; }
        }

  2. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 29 Mar 2012 Link to this post

    Hi Darlene,

    I have tried the code you shared in our labs and it seems to be working correctly. I have prepared for you an application that uses your sample code and shows the configuration of the timebar visually so that you can see what you have configured the timebar with.

    All the best,
    Yavor
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Darlene
    Darlene avatar
    13 posts
    Member since:
    Jan 2012

    Posted 29 Mar 2012 Link to this post

    Hi Yavor,

    Thank you for your help.  With your solution, I was able to narrow down the problem to the way the view model is assigned to the view.  You use XAML, but I had it in the constructor like so:
    public MainWindow()
           {
               InitializeComponent();
               this.DataContext = new ViewModel();
           }

    If I move the DataContext assignment to before the InitializeComponent() call, it works as expected.  But in my actual application, the view model is assigned independently of the view after it has already been created (ie, MyView.DataContext = MyViewModel).  So I need the assignment of a view model after InitializeComponent() to work.  How can I make that happen?

    (Ideally assume I have no knowledge of the view's contents)

  5. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 03 Apr 2012 Link to this post

    Hi Darlene,

    You are right! I have added a button that changes the view model on click and some times the Visible range doesn't get applied. I will forward your report to our development team. You can track this issue in our PITS system here and your telerik points have been updated!

    Regards,
    Yavor
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Darlene
    Darlene avatar
    13 posts
    Member since:
    Jan 2012

    Posted 03 Apr 2012 Link to this post

    Hi Yavor,

    Thanks for your reply.  Note that this is with the TimeBar control (your system lists it under TreeMap).  There is some priority with this, I'll need the fix by the end of the month, hopefully in time for your next release or service pack.

    Thank you,
    - Darlene
  7. Answer
    Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 06 Apr 2012 Link to this post

    Hi Darlene,

    My mistake. I have edited the work item and PITS issue and now it lists the problem under TimeBar for SL/WPF. Don't worry though, because the development team is notified about the issue.

    Meanwhile you can try a simple workaround that refreshes the bindings set on the visible range. Here is some code:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        this.DataContext = new ViewModel();
     
        // HACK: Refresh visible range bindings when changing the view model
        Binding binding1 = BindingOperations.GetBinding(this.timebar, RadTimeBar.VisiblePeriodStartProperty);
        Binding binding2 = BindingOperations.GetBinding(this.timebar, RadTimeBar.VisiblePeriodEndProperty);
        this.timebar.ClearValue(RadTimeBar.VisiblePeriodStartProperty);
        this.timebar.ClearValue(RadTimeBar.VisiblePeriodEndProperty);
        BindingOperations.SetBinding(this.timebar, RadTimeBar.VisiblePeriodStartProperty, binding1);
        BindingOperations.SetBinding(this.timebar, RadTimeBar.VisiblePeriodEndProperty, binding2);
    }

    I have attached a sample application that demonstrates it. All the best,
    Yavor
    the Telerik team

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

  8. Darlene
    Darlene avatar
    13 posts
    Member since:
    Jan 2012

    Posted 09 Apr 2012 Link to this post

    Hi Yavor,

    Thank you very much.  That workaround is acceptable. :)

    - Darlene
  9. Boris Rogge
    Boris Rogge avatar
    30 posts
    Member since:
    Mar 2006

    Posted 19 Nov 2012 Link to this post

    Hi Telerik,

    Has this been fixed in the meantime? We only use MVVM. Hence we cannot use the code behind workaround.

    Thanks
  10. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 22 Nov 2012 Link to this post

    Hello Boris,

    Actually this problem should not affect your MVVM project. If your ViewModel implements INotifyPropertyChanged there is no reason to replace an already set ViewModel with another one.

    By changing the individual properties of the VM the TimeBar will correctly detect the changes and it will refresh its state accordingly.

    However if you experience any problems, I'll be glad to help
     
    Kind regards,
    Petar Kirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  11. Boris Rogge
    Boris Rogge avatar
    30 posts
    Member since:
    Mar 2006

    Posted 27 Nov 2012 Link to this post

    Hello Petar,

    The way our applications are built is by using a control template where content and contenttemplate are dynamically set. So we have a viewmodel first model. In this scenario, the visibility periods are not updated, even though they are bound.

    I will open a support ticket so I can add an example.

    Thanks
  12. fgjd
    fgjd avatar
    1 posts
    Member since:
    Sep 2008

    Posted 28 Nov 2012 Link to this post

    Another workaround is setting VisiblePeriodEnd before VisiblePeriodStart! That worked for me.
Back to Top
UI for WPF is Visual Studio 2017 Ready