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

VisiblePeriodStart Not Set

10 Answers 157 Views
TimeBar
This is a migrated thread and some comments may be shown as answers.
Darlene
Top achievements
Rank 1
Darlene asked on 26 Mar 2012, 07:46 PM
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; }
    }

10 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 29 Mar 2012, 09:52 AM
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 >>
0
Darlene
Top achievements
Rank 1
answered on 29 Mar 2012, 03:24 PM
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)

0
Yavor
Telerik team
answered on 03 Apr 2012, 09:36 AM
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 >>
0
Darlene
Top achievements
Rank 1
answered on 03 Apr 2012, 02:16 PM
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
0
Accepted
Yavor
Telerik team
answered on 06 Apr 2012, 08:38 AM
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 >>

0
Darlene
Top achievements
Rank 1
answered on 09 Apr 2012, 03:46 PM
Hi Yavor,

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

- Darlene
0
Boris Rogge
Top achievements
Rank 1
answered on 19 Nov 2012, 04:29 PM
Hi Telerik,

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

Thanks
0
Petar Kirov
Telerik team
answered on 22 Nov 2012, 02:57 PM
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.

0
Boris Rogge
Top achievements
Rank 1
answered on 27 Nov 2012, 01:27 PM
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
0
fgjd
Top achievements
Rank 1
answered on 28 Nov 2012, 05:34 PM
Another workaround is setting VisiblePeriodEnd before VisiblePeriodStart! That worked for me.
Tags
TimeBar
Asked by
Darlene
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Darlene
Top achievements
Rank 1
Boris Rogge
Top achievements
Rank 1
Petar Kirov
Telerik team
fgjd
Top achievements
Rank 1
Share this question
or