Change CurrentVisibleRangeText

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

    Posted 25 Jul Link to this post

    Hi,

    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"
          VerticalAlignment="Center"
          HorizontalAlignment="Right"
          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">
            <Setter.Value>
                <DataTemplate>
                    <Grid>
                        <TextBlock Margin="0 1 0 0" Text="{Binding Path=Start, StringFormat={}{0:ddd dd/MM/yyyy}}" Foreground="White" />
                    </Grid>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

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

    Posted 27 Jul 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"
            VerticalAlignment="Center"
            HorizontalAlignment="Right"
            Style="{StaticResource NavigationIntervalStyle}">
        <ContentControl.Content>
            <MultiBinding Converter="{StaticResource CurrentVisibleRangeTextConverter}">
                <Binding Path="CurrentVisibleRangeText" RelativeSource="{RelativeSource TemplatedParent}" />
                <Binding Path="ActiveViewDefinition" RelativeSource="{RelativeSource TemplatedParent}" />
                <Binding Path="VisibleRange" RelativeSource="{RelativeSource TemplatedParent}" />
            </MultiBinding>
        </ContentControl.Content>
    </ContentControl>

    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");
        }
        else
        {
            ...
        }
        return values[0];
    }

    I hope this will be helpful.

    Regards,
    Yana
    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. UI for WPF is Visual Studio 2017 Ready
  4. Kieron
    Kieron avatar
    6 posts
    Member since:
    Jan 2016

    Posted 27 Jul in reply to Yana Link to this post

    Perfect thanks.
Back to Top