c# - How can I display the current day of the week in XAML using the current regional settings? -


i have following xaml:

<window x:class="string_format.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         xmlns:s="clr-namespace:system;assembly=mscorlib"         mc:ignorable="d"         title="mainwindow" height="150" width="250">     <stackpanel margin="10">         <textblock name="textblock" text="{binding source={x:static s:datetime.now}, stringformat=date: {0:dddd, mmmm dd}}"/>     </stackpanel> </window> 

in xaml designer in visual studio 2015 in running application, displays as: "date: thursday, january 28". on german windows 7 regional settings set "german (germany)", had expected: "date: donnerstag, januar 28".

so went , added namespace

xmlns:c="clr-namespace:system.globalization;assembly=mscorlib" 

and altered textblock to:

<textblock name="textblock" text="{binding source={x:static s:datetime.now}, converterculture={x:static c:cultureinfo.currentculture}, stringformat=date: {0:dddd, mmmm dd}}"/> 

this indeed results in desired behavior @ runtime, in xaml designer, says "invalid markup", , there's no preview of window displayed more.

this has been asked before, wanted inside xaml, without using code behind, if possible.

so what's wrong xaml? i'd understand.

this indeed results in desired behavior @ runtime, in xaml designer, says "invalid markup", , there's no preview of window displayed more.

this because added code: converterculture={x:static c:cultureinfo.currentculture} cannot resolved @ design time. results in invalid markup , lack of display. is resolved @ runtime, why date displays in correct language/culture.

you can solve moving code can check whether it's runtime or design time.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -