Change CurrentVisibleRangeText

3 posts, 1 answers
  1. Kieron
    Kieron avatar
    8 posts
    Member since:
    Jan 2016

    Posted 25 Jul 2016 Link to this post


    I want to apply a different CurrentVisibleRangeText dependant on what view definition the user is in.

    So DayView would be in the format ddd dd\MM\yyyy

    Timeline and MonthView would be dd\MM\yyyy - dd\MM\yyyy

    So I've changed the CurrentInterval ContentControl to use VisibleRange instead of CurrentVisibleText :

    <ContentControl x:Name="CurrentInterval"
          Style="{StaticResource NavigationIntervalStyle}"
          Content="{TemplateBinding VisibleRange}"/>

    Now how do I apply the NavigationIntervalStyle?  So far I have :

    <Style x:Key="NavigationIntervalStyle" TargetType="ContentControl">
        <Setter Property="Margin" Value="5" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="HorizontalAlignment" Value="Right" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="ContentTemplate">
                        <TextBlock Margin="0 1 0 0" Text="{Binding Path=Start, StringFormat={}{0:ddd dd/MM/yyyy}}" Foreground="White" />

    This works ok for DayView but obviously not giving me what I want for Timeline or MonthView - I would presume I would need another TextBlock linked to VisibleRange.End - but how to set the Visibility of this textbox so I don't get it in DayView?  Also would it be at all feasible for MonthView to run off the actual Month date and not just what is visible.. i.e. so it says 01/07/2016 - 31/07/2016 and not 27/07/2016 - 31/07/2016 (which is the actual VisibleRange of the month).

  2. Answer
    Yana avatar
    4604 posts

    Posted 27 Jul 2016 Link to this post

    Hello Kieron,

    You could use a MultiValueConverter when binding the CurrentVisibleRangeText, so you can receive information on the active ViewDefinition and the VisibleRange and return inside the converter the value formatted per your requirement. Here is some sample code:

    <ContentControl x:Name="CurrentInterval"
            Style="{StaticResource NavigationIntervalStyle}">
            <MultiBinding Converter="{StaticResource CurrentVisibleRangeTextConverter}">
                <Binding Path="CurrentVisibleRangeText" RelativeSource="{RelativeSource TemplatedParent}" />
                <Binding Path="ActiveViewDefinition" RelativeSource="{RelativeSource TemplatedParent}" />
                <Binding Path="VisibleRange" RelativeSource="{RelativeSource TemplatedParent}" />

    and the CurrentVisibleRangeTextConverter class:

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        var viewDef = values[1] as DayViewDefinition;
        if (viewDef != null && viewDef.VisibleDays == 1)
            var currentVisibleRange = values[2] as DateSpan;
            if (currentVisibleRange != null)
                return currentVisibleRange.Start.ToString("d MMMM yyyy");
        return values[0];

    I hope this will be helpful.

    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. Kieron
    Kieron avatar
    8 posts
    Member since:
    Jan 2016

    Posted 27 Jul 2016 in reply to Yana Link to this post

    Perfect thanks.
Back to Top