Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is how I personally would approach something like this. Normally, I would move the members out into a separate logic class and include some other validation in the setters.</p> <pre><code>public partial class MainWindow : Window, INotifyPropertyChanged { public MainWindow() { InitializeComponent(); DataContext = this; } public DateTime Date { get { DateTime dt; if (DateTime.TryParseExact(String.Format("{0}-{1}-{2}", DateYear, DateMonth, DateDay), "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out dt)) return dt; return DateTime.MinValue; } } private string year = "2011"; public String DateYear { get { return year; } set { if (year == value) return; year = value; NotifyPropertyChanged("DateYear"); NotifyPropertyChanged("Date"); } } private string month = "11"; public String DateMonth { get { return month; } set { if (month == value) return; month = value; NotifyPropertyChanged("DateMonth"); NotifyPropertyChanged("Date"); } } private string day = "11"; public String DateDay { get { return day; } set { if (day == value) return; day = value; NotifyPropertyChanged("DateDay"); NotifyPropertyChanged("Date"); } } #region INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(string info) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(info)); } #endregion } </code></pre> <p>And the xaml</p> <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Label&gt;Date:&lt;/Label&gt; &lt;Label Grid.Column="1" Content="{Binding Path=Date}" /&gt; &lt;Label Grid.Row="1"&gt;Year&lt;/Label&gt; &lt;TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=DateYear}" /&gt; &lt;Label Grid.Row="2"&gt;Month&lt;/Label&gt; &lt;TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=DateMonth}" /&gt; &lt;Label Grid.Row="3"&gt;Day&lt;/Label&gt; &lt;TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=DateDay}" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
    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.
    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