C1.xaml.datetimeselector set the minute step

Posted by: roberto_tomasi on 17 September 2017, 5:10 am EST

    • Post Options:
    • Link

    Posted 17 September 2017, 5:10 am EST

    There is a way to set the minute step?

    i don’t want the full list (1,2,3,4,5,6…) but instead i would this short list (0,15,30,45)

    Thank’s

  • Posted 18 September 2017, 3:53 pm EST

    Hi,

    I escalated this to concern team. Will let you know as soon as there is any information from them.

    Thanks,

    Singh

  • Posted 18 September 2017, 5:59 pm EST

    Hi,

    You can find the minutes combobox and change its ItemsSource.

    See the below code:

    <c1:C1DateTimeSelector Height="60" x:Name="dts" />
    
    public sealed partial class MainPage : Page
        {
            List<int> data = new List<int> { 0, 15, 30, 45, 60};
            public MainPage()
            {
                this.InitializeComponent();
                Loaded += MainPage_Loaded;            
            }
    
            private void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
                this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => 
                {
                    var minute = dts.GetChildren<ComboBox>().Where(el => el.Name.Equals("MinutesList")).FirstOrDefault();
                    if (minute != null)
                    {
                        minute.ItemsSource = data;
                        minute.ItemTemplate = null;
                        minute.SelectedIndex = 0;
                    }
                });
                
            }
        }
    
        public static class Extensions
        {
            public static IEnumerable<DependencyObject> GetChildren(this FrameworkElement elem, bool includeSelf = true, bool recursive = true)
            {
                if (elem == null) yield break;
                if (includeSelf) yield return elem;
    
                FrameworkElement current = elem;
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(elem); i++)
                {
                    var child = VisualTreeHelper.GetChild(elem, i);
                    yield return child;
                    if (recursive && child is FrameworkElement)
                    {
                        foreach (var item in (child as FrameworkElement).GetChildren(false, true))
                        {
                            yield return item;
                        }
                    }
                }
            }
    
            public static IEnumerable<T> GetChildren<T>(this FrameworkElement elem) where T : FrameworkElement
            {
                return elem.GetChildren().Where(e => e is T).Select(e => e as T);
            }
        }
    

    Thanks,

    Singh Sonu

  • Posted 27 September 2017, 4:58 am EST

    Thank’s a lot for reply but I would be very grateful for Visual Basic Translate :slight_smile:

  • Posted 27 September 2017, 3:54 pm EST

    Hi,

    Please find the VB code below:

     <my:C1DateTimeSelector Height="60" x:Name="dts"/>
    
    Partial Public NotInheritable Class MainPage
        Inherits Page
        Private data As New List(Of Integer)() From {
            0,
            15,
            30,
            45,
            60
        }
        Public Sub New()
            Me.InitializeComponent()
            AddHandler Loaded, AddressOf MainPage_Loaded
        End Sub
    
        Private Async Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs)
            Await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, Function()
                                                                         Dim minute = FindChild(Of ComboBox)(dts, "MinutesList")
                                                                         If minute IsNot Nothing Then
                                                                             minute.ItemsSource = data
                                                                             minute.ItemTemplate = Nothing
                                                                             minute.SelectedIndex = 0
                                                                         End If
                                                                         Return 0
                                                                     End Function)
        End Sub
    
    
        ''' <summary>
        ''' Finds a Child of a given item in the visual tree. 
        ''' </summary>
        ''' <param name="parent">A direct parent of the queried item.</param>
        ''' <typeparam name="T">The type of the queried item.</typeparam>
        ''' <param name="childName">x:Name or Name of child. </param>
        ''' <returns>The first parent item that matches the submitted type parameter. 
        ''' If not matching item can be found, 
        ''' a null parent is being returned.</returns>
        Public Function FindChild(Of T As DependencyObject)(parent As DependencyObject, childName As String) As T
            ' Confirm parent and childName are valid. 
            If parent Is Nothing Then
                Return Nothing
            End If
    
            Dim foundChild As T = Nothing
    
            Dim childrenCount As Integer = VisualTreeHelper.GetChildrenCount(parent)
            For i As Integer = 0 To childrenCount - 1
                Dim child = VisualTreeHelper.GetChild(parent, i)
                ' If the child is not of the request child type child
                Dim childType As T = TryCast(child, T)
                If childType Is Nothing Then
                    ' recursively drill down the tree
                    foundChild = FindChild(Of T)(child, childName)
    
                    ' If the child is found, break so we do not overwrite the found child. 
                    If foundChild IsNot Nothing Then
                        Exit For
                    End If
                ElseIf Not String.IsNullOrEmpty(childName) Then
                    Dim frameworkElement = TryCast(child, FrameworkElement)
                    ' If the child's name is set for search
                    If frameworkElement IsNot Nothing AndAlso frameworkElement.Name = childName Then
                        ' if the child's name is of the request name
                        foundChild = DirectCast(child, T)
                        Exit For
                    End If
                Else
                    ' child element found.
                    foundChild = DirectCast(child, T)
                    Exit For
                End If
            Next
    
            Return foundChild
        End Function
    End Class
    

    Thanks,

    Singh Sonu

  • Posted 23 October 2017, 3:05 am EST

    Hi

    thanks for your reply but not works fine

    I insert the TimeSelector into a C1TabControl

    it works only in the first TabItem

    in the others TabItem not works because this line

    Dim childrenCount As Integer = VisualTreeHelper.GetChildrenCount(parent)

    return 0

  • Posted 2 November 2017, 11:47 pm EST

    Help Please :slight_smile:

  • Posted 5 November 2017, 4:46 pm EST

    Hi,

    Yes, I could replicate the same issue at my end and escalated this to concern team. Will let you know as soon as there is any information from them.

    (Tfs id: 286433 for internal use only)

    Thanks,

    Singh

  • Posted 8 November 2017, 5:51 pm EST

    Hi,

    It might be a limitation to implement this request in an easy way. As investigated, I provided a workaround to make this request. Please refer to attached sample.

    Thanks,

    Singh

    DateTimeSelectorTest.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels