I have run out of ideas for trying to change the DatePicker Format property in XAML using OnIdiom. I have tried using XAML styles, I have tried defining the string in a Constants.cs file and referencing it from XAML. The only other way I can think of would be to extended the DatePicker and set it in there. Has anyone gotten this to work?
Things that did not work are listed below.
Global Style with OnIdiom:
<Style TargetType="DatePicker">
<Setter Property="Format">
<OnIdiom x:TypeArguments="x:String"
Tablet="D"
Phone="d"/>
</Setter>
</Style>
Global style referencing a string defined in my Constants.cs class file, which uses Device.Idiom == TargetIdiom.Phone ? "d" : "D";
<Style TargetType="DatePicker">
<Setter Property="Format" Value="{x:Static map:Constants.LongDateTimeStringFormat}"/>
</Style>
Trying to only define the string with a key:
<OnIdiom x:Key="LongDateTimeStringFormat"
x:TypeArguments="x:String"
Tablet="D"
Phone="d"/>
Trying to only define the string with a key another way:
<x:String x:Key="LongDateTimeStringFormat">
<OnIdiom x:TypeArguments="x:String"
Tablet="D"
Phone="d"/>
</x:String>
It also does not work when trying to use <OnIdiom> within the <DatePicker.Format> directly, without styles, or trying to set the DatePicker.Format to {x:Static map:Constants.LongDateTimeStringFormat}.
Well... it seems to be working now in a different project. Adding the following global style does not give me a format exception like it did yesterday.
<Style TargetType="DatePicker">
<Setter Property="Format">
<OnIdiom x:TypeArguments="x:String"
Tablet="D"
Phone="d"/>
</Setter>
</Style>
May have to investigate a little later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With