RadComboBox and MinorTickLength

5 posts, 1 answers
  1. Krzysztof
    Krzysztof avatar
    14 posts
    Member since:
    Oct 2007

    Posted 20 Feb 2013 Link to this post

    Dear Telerik Team!

    I'm trying to create some kind of configuration tool for ScheduleView control view settings. I'd like to initialize ScheduleView with some default values for orientation, visible days, minor and major tick length. In one of my xaml user controls code I have radcombobox definied:
    <telerik:RadComboBox
                    ItemsSource="{Binding MinorTickProviders}"
                    SelectedItem="{Binding SchedulerViewSettings.MinorTickLength,Mode=TwoWay}">
                    <telerik:RadComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding ., Converter={StaticResource TickConverter}}" />
                        </DataTemplate>
                    </telerik:RadComboBox.ItemTemplate>
                </telerik:RadComboBox>

    ComboBox ItemsSource is definied like this:
    private List<ITickProvider> minorTickProviders;
    public List<ITickProvider> MinorTickProviders
            {
                get
                {
                    return this.minorTickProviders;
                }
    }
     
    this.minorTickProviders = new List<ITickProvider>();
    this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(2, 0, 0, 0, 0)));
    this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(5, 0, 0, 0, 0)));
    this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(10, 0, 0, 0, 0)));
    this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(15, 0, 0, 0, 0)));
    this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(20, 0, 0, 0, 0)));
    this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(30, 0, 0, 0, 0)));
    this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(0, 1, 0, 0, 0)));
    this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(0, 2, 0, 0, 0)));
    this.minorTickProviders.Add(AutomaticTickLengthProvider.MinorProvider);

    I also use this converter:
    public class TickConverter : IValueConverter
            {
                public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
                {
                    FixedTickProvider provider = value as FixedTickProvider;
     
                    if (provider != null)
                    {
                        string interval = string.Format("{0:d2}:{1:d2}:00", provider.Interval.Hours, provider.Interval.Minutes);
                        if (provider.Interval.Hours == 0 && provider.Interval.Minutes == 0)
                        {
                            if (provider.Interval.Days == 1)
                            {
                                interval = "1 day";
                            }
                            else
                            {
                                interval = string.Format("{0} days", provider.Interval.Days);
                            }
                        }
                        return interval;
                    }
                    return "Automatic conversion";
                }
     
                public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
                {
                    throw new NotImplementedException();
                }
            }

    I bind combobox SelectedItem property to the following field:
    private ITickProvider mMinorTickLenght;
            public ITickProvider MinorTickLength
            {
                get { return mMinorTickLenght; }
                set
                {
                    mMinorTickLenght = value;
                }
            }
     
    MinorTickLength = new FixedTickProvider(new DateTimeInterval(20, 0, 0, 0, 0));

    But it doesn't work. ComboBox item is not selected. Could you please help me and point me in to the right direction?

    Thanks in advance
    Very best regards!
    Krzysztof Kaźmierczak


    testst
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 25 Feb 2013 Link to this post

    Hi Krzysztof,

    I would suggest to check this online example - note the ComboBoxes in the configurator on the left -  they change the MinorTickLength and MajorTickLength properties of the ScheduleView.

    Regards,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Krzysztof
    Krzysztof avatar
    14 posts
    Member since:
    Oct 2007

    Posted 27 Feb 2013 Link to this post

    Dear Yana,

    Thank you for your answer. This sample is very helpful, but I still have problem initializing combobox containing list of ITickProvider items. Is it possible for you to have a look at this very simple sample project files and suggest why combobox value is not set? Thank you very much in advance!.

    My xaml:

    <Window x:Class="TickLengthSample.MainWindow"
            xmlns:local="clr-namespace:TickLengthSample"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <local:TickConverter x:Key="TickConverter"/>
        </Window.Resources>
        <Grid>
            <Grid.DataContext>
                <local:ViewModel />
            </Grid.DataContext>
            <Grid.RowDefinitions>
                <RowDefinition Height="30"></RowDefinition>
                <RowDefinition Height="30"></RowDefinition>
            </Grid.RowDefinitions>
     
            <telerik:RadComboBox Grid.Row="0" ItemsSource="{Binding MinorTickProviders}"
                                 telerik:StyleManager.Theme="Metro" VerticalAlignment="Center"
                                 SelectedValue="{Binding MinorTickLength}"
                                 >
     
                <telerik:RadComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding ., Converter={StaticResource TickConverter}}" />
                    </DataTemplate>
                </telerik:RadComboBox.ItemTemplate>
            </telerik:RadComboBox>
     
            <telerik:RadComboBox ItemsSource="{Binding Bands}" Grid.Row="1"
                                 telerik:StyleManager.Theme="Metro" VerticalAlignment="Center"
                                 SelectedValue="{Binding Band}"
                                 >
                <telerik:RadComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding .}" />
                    </DataTemplate>
                </telerik:RadComboBox.ItemTemplate>
                </telerik:RadComboBox>
        </Grid>
    </Window>

    Converter code (taken from sample you mentioned above):

    namespace TickLengthSample
    {
        public class TickConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                FixedTickProvider provider = value as FixedTickProvider;
     
                if (provider != null)
                {
                    string interval = string.Format("{0:d2}:{1:d2}:00", provider.Interval.Hours, provider.Interval.Minutes);
                    if (provider.Interval.Hours == 0 && provider.Interval.Minutes == 0)
                    {
                        if (provider.Interval.Days == 1)
                        {
                            interval = "1 day";
                        }
                        else
                        {
                            interval = string.Format("{0} days", provider.Interval.Days);
                        }
                    }
                    return interval;
                }
                return "Automatic conversion";
            }
     
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }
    }

    and ViewModel code;

    namespace TickLengthSample
    {
        public class ViewModel : ViewModelBase
        {
            private List<string> bands;
            public List<string> Bands
            {
                get
                {
                    return this.bands;
                }
            }
     
            private List<ITickProvider> minorTickProviders;
            public List<ITickProvider> MinorTickProviders
            {
                get
                {
                    return this.minorTickProviders;
                }
            }
     
            private ITickProvider mMinorTickLength;
            public ITickProvider MinorTickLength
            {
                get { return mMinorTickLength; }
                set
                {
                    mMinorTickLength = value;
                    this.OnPropertyChanged("MinorTickLength");
                }
            }
     
            private string band;
            public string Band
            {
                get { return band; }
                set
                {
                   band = value;
                    this.OnPropertyChanged("Band");
                }
            }
     
            public ViewModel()
            {
                this.minorTickProviders = new List<ITickProvider>();
                this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(2, 0, 0, 0, 0)));
                this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(5, 0, 0, 0, 0)));
                this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(10, 0, 0, 0, 0)));
                this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(15, 0, 0, 0, 0)));
                this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(20, 0, 0, 0, 0)));
                this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(30, 0, 0, 0, 0)));
                this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(0, 1, 0, 0, 0)));
                this.minorTickProviders.Add(new FixedTickProvider(new DateTimeInterval(0, 2, 0, 0, 0)));
                this.minorTickProviders.Add(AutomaticTickLengthProvider.MinorProvider);
     
                MinorTickLength = new FixedTickProvider(new DateTimeInterval(15, 0, 0, 0, 0));
     
                this.bands = new List<string>();
                bands.Add("Running Wild");
                bands.Add("Metallica");
                bands.Add("Judas Priest");
     
                Band = "Metallica";
            }
        }
    }


    Best regards and thank you for your help
    Krzysztof
  5. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 01 Mar 2013 Link to this post

    Hello Krzysztof,

    You should set the SelectedValue of the ComboBox to an item from the ItemSource collection like this:

    MinorTickLength = this.minorTickProviders[3];


    Greetings,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Krzysztof
    Krzysztof avatar
    14 posts
    Member since:
    Oct 2007

    Posted 14 Mar 2013 Link to this post

    Thank you!

    Regards
    Krzysztof Kaźmierczak
Back to Top
UI for WPF is Visual Studio 2017 Ready