'Showing datepicker in Itemcontrol in wpf

I am using Itemscontrol with wrappanel being used as ItempanelTemplate. The ItemTemplate using datatemplate containg of combobox.

The combobox contains list of items and when "custom" option is choosen I need to change the combobox control to show start date and end date fields to choose date from calender. The other comboboxes should remain intact.

MainWindow.xaml

<Window x:Class="ICExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ICExample" xmlns:system="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <ItemsControl ItemsSource="{Binding}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <ComboBox ItemsSource="{Binding TimeFrame}" Margin="0,0,5,5" Width="90" Height="60" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</Window>

MainWindox.xaml.cs

public partial class MainWindow : Window
{
    
    List<Person> personList = new List<Person>();
    

    public MainWindow()
    {
        InitializeComponent();
        Populate();

        DataContext = this.personList;
    }

    private void Populate()
    {
        personList.Add(new Person() { TimeFrame = { "1 month", "1 day", "1 year", "custom" } });
        personList.Add(new Person() { TimeFrame = { "1 month", "1 day", "1 year", "custom" } });
        personList.Add(new Person() { TimeFrame = { "1 month", "1 day", "1 year", "custom" } });
        personList.Add(new Person() { TimeFrame = { "1 month", "1 day", "1 year", "custom" } });
    }        
}

public class Person
{
    private List<string> _timeFrame = new List<string>();
    public List<string> TimeFrame 
    {
        get
        {
            return _timeFrame;
        } 
        set
        {
            _timeFrame = value;
        }
    }
}
wpf


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source