Wpf 组合框样式的日期选择器控件选项

Wpf 组合框样式的日期选择器控件选项,wpf,wpfdatagrid,Wpf,Wpfdatagrid,我正在寻找一个日期选择器,它使用组合框而不是日历样式,就像这样,我现在使用这个控件,但我真的想知道是否还有其他东西 谢谢大家,对不起我的英语。你应该这样做你的自定义控件。。。 You should make your Custom Control like this... <UserControl x:Class="WpfApplication2.ucCalender" xmlns="http://schemas.microsoft.com/winfx/2006/xa

我正在寻找一个日期选择器,它使用组合框而不是日历样式,就像这样,我现在使用这个控件,但我真的想知道是否还有其他东西

谢谢大家,对不起我的英语。

你应该这样做你的自定义控件。。。
You should make your Custom Control like this...

 <UserControl x:Class="WpfApplication2.ucCalender"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="50" d:DesignWidth="301">
<Grid Height="48" Width="303">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100*" />
        <ColumnDefinition Width="100*" />
        <ColumnDefinition Width="100*" />
    </Grid.ColumnDefinitions>
    <ComboBox Height="30" HorizontalAlignment="Left" Margin="2,2,2,2" Name="cmbDays" VerticalAlignment="Top" Width="95" />
    <ComboBox Grid.Column="1" Height="30" HorizontalAlignment="Left" Margin="2,2,2,2" Name="cmdMonths" VerticalAlignment="Top" Width="95" SelectionChanged="cmdMonths_SelectionChanged" />
    <ComboBox Grid.Column="2" Height="30" HorizontalAlignment="Left" Margin="02,2,2,2" Name="cmbYear" VerticalAlignment="Top" Width="95" SelectionChanged="cmbYear_SelectionChanged" />
</Grid>

命名空间WpfApplication2
{
/// 
///ucCalender.xaml的交互逻辑
/// 
公共部分类UCCalendar:UserControl
{
整数[]天=新整数[31];
字符串[]个月;
列表年份=新列表();
公共日历()
{
初始化组件();
初始化列表();
LoadMonthsCombos();
LoadYearCombo();
初始化的数组();
LoadDaysCombo();
}
公共无效初始值设定项()
{
monthNames=DateTimeFormatInfo.CurrentInfo.monthNames;
years=Enumerable.Range(DateTime.Now.Year-60100.ToList();
}
public void initializedAysArray()
{
int month=DateTimeFormatInfo.CurrentInfo.MonthNames.ToList().IndexOf(cmdMonths.SelectedValue.ToString())+1;
天=新整数[DateTime.DaysInMonth(转换为32(cmbYear.SelectedValue),月)];
对于(int i=0;i


关于LoadMonthsCombo()

我不得不使用它,因为它在12月后的第二天生成了13个选项,结果是一片空白,导致程序崩溃。 也是关于初始化列表()

namespace WpfApplication2
{
/// <summary>
/// Interaction logic for ucCalender.xaml
/// </summary>
public partial class ucCalender : UserControl
{
int[] Days = new int[31];
    string[] monthNames;
    List<int> years = new List<int>();



    public ucCalender()
    {
        InitializeComponent();
        initializeLists();            
        LoadMonthsCombos();
        LoadYearCombo();
        initalizeDaysArray();
        LoadDaysCombo();


    }
    public void initializeLists()
    {
        monthNames = DateTimeFormatInfo.CurrentInfo.MonthNames;
        years = Enumerable.Range(DateTime.Now.Year - 60, 100).ToList();
    }
    public void initalizeDaysArray()
    {
        int month = DateTimeFormatInfo.CurrentInfo.MonthNames.ToList().IndexOf(cmdMonths.SelectedValue.ToString()) + 1;
        Days = new int[DateTime.DaysInMonth(Convert.ToInt32(cmbYear.SelectedValue),month)];
        for (int i = 0; i < Days.Count(); i++)
        {
            Days[i] = i+1;
        }


    }
    public void LoadDaysCombo()
    {
        cmbDays.ItemsSource = Days;
        cmbDays.SelectedValue = DateTime.Now.Day;
    }
    public void LoadYearCombo()
    {
        cmbYear.ItemsSource = years;
        cmbYear.SelectedValue = DateTime.Now.Year;
    }
    public void LoadMonthsCombos()
    {            


        cmdMonths.ItemsSource = monthNames;
        cmdMonths.SelectedValue = DateTimeFormatInfo.CurrentInfo.GetMonthName(DateTime.Now.Month);            


    }

    private void cmdMonths_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (cmdMonths.SelectedValue != null)
        {
            initalizeDaysArray();
            LoadDaysCombo();
        }
    }

    private void cmbYear_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (cmbYear.SelectedValue != null)
        {
            initalizeDaysArray();
            LoadDaysCombo();
        }
    }
   }
 }

  USE IT LIKE THIS IN ANY WINDOW
   <Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:myCalender="clr-namespace:WpfApplication2"       
    Title="MainWindow" Height="295" Width="431">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="6*" />
        <RowDefinition Height="46*" />
        <RowDefinition Height="106*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="6*" />
        <ColumnDefinition Width="52*" />
        <ColumnDefinition Width="301*" />
    </Grid.ColumnDefinitions>
    <myCalender:ucCalender Grid.Row="1" Grid.Column="2" Width="300" Height="50"/>
</Grid>
cmbMonths.ItemsSource = monthNames.Take(12).ToList();
 monthNames = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames;