Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Get rid of DataGridTextColumn and use DataGridTemplateColumn with CellTemplate containing a textblock bound to your multibinding, and cell editing template containing TextBox bound to FromDate, possibly via short-date converter, depending on usability you intend to achieve.</p> <p>On of possible solutions:</p> <p><strong>XAML</strong></p> <pre><code> &lt;StackPanel&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Label&gt;From time&lt;/Label&gt; &lt;DatePicker SelectedDate="{Binding FromTime}"/&gt; &lt;/StackPanel&gt; &lt;DataGrid ItemsSource="{Binding AllUsers}" AutoGenerateColumns="False"&gt; &lt;DataGrid.Resources&gt; &lt;local:TimeConverter x:Key="TimeConverter"/&gt; &lt;/DataGrid.Resources&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTemplateColumn&gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate DataType="local:UserViewModel"&gt; &lt;TextBlock&gt; &lt;TextBlock.Text&gt; &lt;MultiBinding Converter="{StaticResource TimeConverter}"&gt; &lt;Binding ElementName="root" Path="DataContext.FromTime"/&gt; &lt;Binding Path="AttendTimeHour"/&gt; &lt;Binding Path="AttendTimeMinute"/&gt; &lt;/MultiBinding&gt; &lt;/TextBlock.Text&gt; &lt;/TextBlock&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;DataGridTemplateColumn.CellEditingTemplate&gt; &lt;DataTemplate DataType="local:UserViewModel"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock&gt; &lt;Run&gt;Attend on &lt;/Run&gt; &lt;Run Text="{Binding ElementName=root, Path=DataContext.FromTime, StringFormat=d}"/&gt; &lt;Run&gt; at &lt;/Run&gt; &lt;/TextBlock&gt; &lt;TextBox Text="{Binding AttendTimeHour}"/&gt;&lt;TextBlock&gt;:&lt;/TextBlock&gt; &lt;TextBox Text="{Binding AttendTimeMinute}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellEditingTemplate&gt; &lt;/DataGridTemplateColumn&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; &lt;/StackPanel&gt; </code></pre> <p><strong>View model (UserViewModel) part:</strong></p> <pre><code> private DateTime _attendTime; public DateTime AttendTime { get { return _attendTime; } set { if (value == _attendTime) return; _attendTime = value; OnPropertyChanged(); OnPropertyChanged("AttendTimeHour"); OnPropertyChanged("AttendTimeMinute"); } } public int AttendTimeHour { get { return attendTimeHour; } set { if (value.Equals(attendTimeHour)) return; attendTimeHour = value; AttendTime = new DateTime(AttendTime.Year, AttendTime.Month, AttendTime.Day, AttendTimeHour, AttendTime.Minute, AttendTime.Second); OnPropertyChanged(); } } private int _attendTimeMinute; public int AttendTimeMinute { get { return _attendTimeMinute; } set { if (value == _attendTimeMinute) return; _attendTimeMinute = value; AttendTime = new DateTime(AttendTime.Year, AttendTime.Month, AttendTime.Day, AttendTime.Hour, AttendTimeMinute, AttendTime.Second); OnPropertyChanged(); } } </code></pre> <p><strong>And the converter</strong></p> <pre><code> public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.Length &lt; 2) return null; if (!(values[0] is DateTime &amp;&amp; values[1] is int &amp;&amp; values[2] is int)) return null; var fromDate = (DateTime) values[0]; var attendTimeHour = (int) values[1]; var attendTimeMinutes = (int)values[2]; var result = new DateTime(fromDate.Year, fromDate.Month, fromDate.Day, attendTimeHour, attendTimeMinutes, 0); return result.ToString(); } </code></pre>
    singulars
    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