Note that there are some explanatory texts on larger screens.

plurals
  1. POwpf custom user control
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/7223345/wpf-custom-datepicker-user-control">Wpf custom datepicker user control</a> </p> </blockquote> <p>i want to create a user control for getting date from user that have 3 textbox for year, month and day but i dont know how to create it. please help me</p> <pre><code>&lt;UserControl x:Class="UI.WPF.CustomControls.ChooseDateControl" 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" x:Name="chooseDateControl" xmlns:custom="clr-namespace:UI.WPF.CustomControls" d:DesignHeight="26" d:DesignWidth="181" FontFamily="Tahoma"&gt; &lt;DockPanel LastChildFill="True"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="1.5*" /&gt; &lt;ColumnDefinition Width="14" /&gt; &lt;ColumnDefinition Width="1*" /&gt; &lt;ColumnDefinition Width="14" /&gt; &lt;ColumnDefinition Width="1*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Label Content="/" Grid.Column="1" /&gt; &lt;Label Content="/" Grid.Column="3" /&gt; &lt;custom:NumericTextBox x:Name="txtYear" ToolTip="سال" Text="{Binding ElementName=chooseDateControl, Mode=TwoWay, Path=Year}" MaxLength="4" TabIndex="2" MinWidth="20" /&gt; &lt;custom:NumericTextBox x:Name="txtMonth" Grid.Column="2" ToolTip="ماه" Text="{Binding ElementName=chooseDateControl, Mode=TwoWay, Path=Month}" MaxLength="2" TabIndex="1" MinWidth="20" /&gt; &lt;custom:NumericTextBox x:Name="txtDay" Grid.Column="4" ToolTip="روز" Text="{Binding ElementName=chooseDateControl, Mode=TwoWay, Path=Day}" MaxLength="2" TabIndex="0" MinWidth="20" /&gt; &lt;/Grid&gt; &lt;/DockPanel&gt; </code></pre> <p>and this is the code behind:</p> <pre><code>public partial class ChooseDateControl : UserControl { public static readonly DependencyProperty ValueProperty; public static readonly DependencyProperty YearProperty; public static readonly DependencyProperty MonthProperty; public static readonly DependencyProperty DayProperty; static ChooseDateControl() { ValueProperty = DependencyProperty.Register( "Value", typeof(DateTime), typeof(ChooseDateControl), new FrameworkPropertyMetadata(DateTime.MinValue)); ValueProperty = DependencyProperty.Register( "Year", typeof(int), typeof(ChooseDateControl), new FrameworkPropertyMetadata((int)0, new PropertyChangedCallback(OnYearChanged))); ValueProperty = DependencyProperty.Register( "Month", typeof(int), typeof(ChooseDateControl), new FrameworkPropertyMetadata((int)0, new PropertyChangedCallback(OnMonthChanged))); ValueProperty = DependencyProperty.Register( "Day", typeof(int), typeof(ChooseDateControl), new FrameworkPropertyMetadata((int)0, new PropertyChangedCallback(OnDayChanged))); } public ChooseDateControl() { InitializeComponent(); } private static void OnDayChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { DateTime newDate = (DateTime)e.NewValue; DateTime oldDate = (DateTime)e.OldValue; NumericTextBox dayPicker = (NumericTextBox)sender; dayPicker.Text = newDate.Day.ToString(); } private static void OnMonthChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { DateTime newDate = (DateTime)e.NewValue; DateTime oldDate = (DateTime)e.OldValue; NumericTextBox monthPicker = (NumericTextBox)sender; monthPicker.Text = newDate.Month.ToString(); } private static void OnYearChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { DateTime newDate = (DateTime)e.NewValue; DateTime oldDate = (DateTime)e.OldValue; NumericTextBox yearPicker = (NumericTextBox)sender; yearPicker.Text = newDate.Year.ToString(); } public DateTime Value { get { return (DateTime)base.GetValue(ValueProperty); } set { base.SetValue(ValueProperty, value); } } public int Year { get { return (int)base.GetValue(YearProperty); } set { base.SetValue(YearProperty, value); } } public int Month { get { return (int)base.GetValue(MonthProperty); } set { base.SetValue(MonthProperty, value); } } public int Day { get { return (int)base.GetValue(DayProperty); } set { base.SetValue(DayProperty, value); } } } </code></pre> <p>it don't work correctly and return the default value that is the DateTime.MinValue. i know this is wrong. please help me</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload