Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, for those that happen to run into the same issue, here's what I finally did:</p> <p>In XAML:</p> <pre><code>&lt;src:ConvertMinDate x:Key="ConvertMinDate"/&gt; &lt;Style TargetType="{x:Type my:DatePicker}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding Path=SelectedDate, RelativeSource={RelativeSource Self}, Converter={StaticResource ConvertMinDate}}" Value="True"&gt; &lt;Setter Property="Foreground" Value="DarkGray"/&gt; &lt;Setter Property="ToolTip" Value="Select a date"/&gt; &lt;Setter Property="FontStyle" Value="Italic"/&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>In codebehind:</p> <pre><code>public class ConvertMinDate : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return true; } else { DateTime date = Peche.Properties.Settings.Default.MinDate; if (value is DateTime) { date = (DateTime)value; return date == Peche.Properties.Settings.Default.MinDate; } else { return true; } } } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } </code></pre> <p>MinDate has been set to 1st of january 1990 in the Settings section of my project.</p> <p>So now, if the SelectedDate is either null or equals MinDate, the converted return true, thus triggering the DataTrigger and changing the style if the DatePickerTextBox.</p> <p>Isn't WPF just great? :-)</p>
 

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