Note that there are some explanatory texts on larger screens.

plurals
  1. POWpf custom datepicker user control
    primarykey
    data
    text
    <p>I want to create a user control for getting a date from the user. It should have three textboxes, one for year, month and day. I don't know how to create it.</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></p> <p><strong>Code Behind</strong></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)); ValueProperty = DependencyProperty.Register( "Month", typeof(int), typeof(ChooseDateControl), new FrameworkPropertyMetadata((int)0)); ValueProperty = DependencyProperty.Register( "Day", typeof(int), typeof(ChooseDateControl), new FrameworkPropertyMetadata((int)0)); } public ChooseDateControl() { InitializeComponent(); } 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 doesn't work correctly-- it returns the default value, which is DateTime.MinValue. 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.
 

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