Home » WPF

DatePicker day colors WPF 4

I  have the following style for the text block in the dictionary

<StyleTargetType="{x:Type TextBlock}"><SetterProperty="HorizontalAlignment"Value="Left"/><SetterProperty="VerticalAlignment"Value="Center"/><SetterProperty="Margin"Value="5,0,0,0 "/><SetterProperty="Foreground"Value="White"/></Style>

after setting this in the resource dictionary, all the text block i have used in my project have foreground color to white which I have set, now the problem is that the datepicker control when open only shows the selected date, as I have set the foreground color of white for the text block in the above style the date picker control dates are not showing. Please help me as soon as possible as I am stuck in this problem :(


15 Answers Found


Answer 1

hi there,

by definition it is suppose to do exactly the same as you are describing,You have to define the x:key attribute and then assign the style  of that particular textblock,or you have to change the TextBlock Foreground into the datePicker,



Answer 2

TheKiller: thanks for your response, your idea of setting  the key for the style  is fine, but the problem  is that I have use hundrand of textBlock control  in my application ,  if I set  the key to the style then I have to set the individual text  block  style, which is time consuming and what I want is to set the color  of the date  inside the date picker  control , if you have any idea about it then it will be fine as I am searhing on google but can't fine a good solution .

Answer 3

Hi Asim,

DatePicker has TextBlock inside it if you see it in Visual Tree

dont specify style  for textblock globaly because most of the controls have TEXTBLOCK inside them..

i've faced the same problem...

so give style name and apply only where you need....

<Style x:Name="MyStyle" TargetType="{x:Type TextBlock}">
      <Setter Property="HorizontalAlignment" Value="Left" />
      <Setter Property="VerticalAlignment" Value="Center" />
      <Setter Property="Margin" Value="5,0,0,0 "/>
      <Setter Property="Foreground" Value="White" />

i hope this will help  you..

Mark it as answer if it helps you..




Answer 4

Try out this,

i've just read ur reply to the first post after replying to ur question





set textblock's color  here ..

Mark it as answer if it helps you..



<DatePicker Height="25" Width="150" TextBlock.Foreground="Red"/>

Answer 5

Thanks for your reply but I want to set  the style  for the text  block color  for the date  picker control  and then place it in the main resource  dictionary




Answer 6

Try out this

 <Style x:Name="MyStyle" TargetType="{x:Type DatePicker}">
      <Setter Property="HorizontalAlignment" Value="Left" />
      <Setter Property="VerticalAlignment" Value="Center" />
      <Setter Property="Margin" Value="5,0,0,0 "/>
      <Setter Property="Foreground" Value="Green" />

Answer 7

I think there is misunderstand, the text  block which show the selected  date along with the date  button which is used to show the dropdown to select the date is not problem  here, the problem here is the dropdown which show the month view, year and decade is creating problem , and I can't see the the date, month or decade value, I have tried all the above solution but could get the required result



Answer 8


Try binding the foreground  to "{TemplateBinding Foreground}"


Answer 9

Can u pls put ur XAML here as i am unable to reproduce ur problem..

Answer 10

here is my complete code , first is the style  which I have used for the text  block and after that is the date  picket control  which is when clicked the dropdown shown but the dates  are not visible hope that will help.

<Stylex:Name="MyStyle"TargetType="{x:Type TextBlock}"><SetterProperty="HorizontalAlignment"Value="Left"/><SetterProperty="VerticalAlignment"Value="Center"/><SetterProperty="Margin"Value="5,0,0,0 "/><SetterProperty="Foreground"Value="White"/></Style>



Answer 11

Mutehsan: can you please give more explaination of your answer to which property will be used to bind


Answer 12


Please use this style, now by doing this the foreground  of textblock will be same as you set  on textblock control

<Style TargetType="{x:Type TextBlock}">
  <SetterProperty="Margin"Value="5,0,0,0 "/>
  <SetterProperty="Foreground"Value="{TemplateBinding Foreground}"/>

e.g. your textblock foreground color  is red then style  will show red on that textblock

<TextBlock Foreground="Red"/>




Answer 13

I have used style  not the template so the Foreground property will be not visible and it will give error

Answer 14


The dropdown control  in a DatePicker is a Calendar. It consists of other controls like CalendarItem, CalendarButton, CalendarDayButton, etc. if I'm not mistaken. I've styled one to make it look like Outlook's month view calendar here. You can download the source code and check which control's style  you need to modify. I'm not sure if you can change the foreground  using the DatePicker though. Hope this helps.


Answer 15

Thanks for your response but can you provide me the style  or template which is used as default style/template and my whole problem  solved ? I am stuck  and I found really difficult to understand the code please if you help  me that will be nice of you


Hi all,

My problem is: I want to display only month and year (mm/yyyy) with DatePicker in wpf. Please help me!


I've been trawling all the different templates of the Cosmopolitan Theme trying to hunt down the setting for the isEnabled = true text color of the DatePicker control.

The default color is to light (gray), and is almost invisible in my UI.

How do I find and change this template setting.

Thanks in advance.




I am using WPF date picker in my application. In that control, If click the date at the top, it opens me up a month calendar and if I click the month in the top, it opens up a year calendar. It' work fine till this point. The issue now is, if I select the year 2010 from the year calendar, it selects 2020. Is any property needs to be set to prevent this?

Thanks in Advance !!!

Best Regards,
Subalakshmi Vijayarajan.


I have a DatePicker Control in my WPF application in which i am trying to display the date as well as time.

But the DatePicker control does not display time like in Windows ?

1.How do i get to do that ?

2.I see that the DatePicker.TimeofDay is set to 12:00:00 whatever day i select from the datepicker control.

But i want to set it to the Current TimeofDay. How can i do this given that timeofday is a read only property ?



When i type in the date on the date picker and check it on an lostfocus event and i try to read the text or selecteddate its blank?  Am i missing something.  I assumed typing in 5/11/2010 on the input box would either show up on the controls Text or the SelectedDate, but i may be missing something





The VisualStateBehaviourFactory in WPF Toolkit (VSM) makes memory leak when use DatePicker. In the reference path it holds the list of VisualStateBehavior instances, the VisualStateBeahvior  holds ButtonBaseBehavior and this ButtonBaseBehavior holds the CalendarButton instances. This leads the DatePicker object still alive in the memory after closing the  application that contain the DatePicker control.





I'm currently writting an application for the French market using a US version of Visual Studio 2010. I'm using DatePickers and I noticed on my machine (also with an English version of Windows) that there is a "Select a date" text.

I would like to make sure that my French clients don't see this. Is there any way to achieve this? 




How can I change a color of the current day marker (vertical line, now yellowish, not visible much on white background) in a gantt view ?




I have a datagrid which is style in black theme. But when i resize the last column and shrink the width the header size left after shrinking is default color of grid. Can we change that color.

I have googled lot about this but no help. only get the style to color the header but not the remaining part left of grid header are resizing or shrinking grid column


Any help/


Hi everybody, i want to change the color of chart background to become transparent. Not the main canvas one, but the grey-white gradient behind the chart. Changing with the properties doesn't override the background color..

Please help me :). Thanks



I have a datagrid control on my xaml window which has some columns like Status, Quantity, Total, Amount.

Now I want to change the backcolor of the columns Total and Amount if some condition is true.

ie                   if (true) Column.background = Red
                      else    Column.background = Green

I tried different events of wpf datagrid but none helped! I am neither able to access these columns from my code nor apply style to them at runtime.

Please help me

I saw some converter classes but didnt understand



I'm creating a custom control for my WPF application, and I'd like to know how I can invert the colors of the control when it's clicked.  I've gotten it to respond to mouse clicks, but when I try swapping the background and foreground brushes, only the background color changes.  The control is a die control and I want the colors to be inverted when it's selected.  I created the die faces by using a grid in the control template and placing ellipses with their fill brushes set to {TemplateBinding Foreground}.  Any help would be greatly appreciated.



How can i dynamically create colors , which i want to asigned to the Columns in a WPF toolkit Chart control.

i want the colors, which are suitable to the chart control (like the ones which are by default generated).



How can I set this value..
Hey, I have a Main Window (MainWindow.xaml) in this I have a tabControl contain an item of type DIGITALTypeControl.xaml

 <MY_WPF_DIC:DIGITALTypeControl x:Name="DINControl"/>
This control (DIGITALTypeControl), contains a DataTemplate for a button:
<DataTemplatex:Key="DOTItemTemplate"><ButtonStyle="{StaticResource RoundButton}"Height="20"Width="20"Background="Red"Name="btnDOT"Click="btnDOT_Click"/></DataTemplate>

RoundButton is contained a ResourceDictionary.

In my MainWindow, I link the digital control to an ObservableCollection, this contains a "value" which can be either 0 or 1.

I want to changed the buttons background color according to this value, 0 = red and 1 = green and when the button is pressed the value must toggle, 0 becomes 1......

How can this be accomplish?


Hi. I have a richtextbox and a toolbar with colors. I want to be able to set color of the text that will be typed after current carret position. For example I have a text in red color and cursor is at the end of the typed text. Now when I click the button with black, I want next typed text to be black.  It is easy to apply color on selection using Selection.ApplyPropertyValue but this doesnt work if selection is empty. I guess I must somehow create a new section or something like that after carret position. That way it will have different foreground property. I just cant figure it out. Any ideas?

Sorry in advance if this is simple, but for the life of me I can't get this to work.  I have the multi point/color working in XAML but I want to pass VB variables (for color and offset) to it.  There are HEAPS of C++ examples but sadly no VB, I've written this before as a VB Form and cheated by having several rectangles with single stage gradians that repositioned/resized based upon the transition point.  So far the XMAL is shaping up as such...

<Rectangle Name="GRADIAN" Stroke="Black" Width="40" HorizontalAlignment="Right" Margin="0,12,120.727,172">


    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">

     <GradientStop Color="White" Offset="0"  />

     <GradientStop x:Name="Colour1" Offset="0.1" />

     <GradientStop x:Name="Colour2" Offset="0.2" />

     <GradientStop x:Name="Colour3" Offset="0.4" />

     <GradientStop x:Name="Colour4" Offset="0.6" />

     <GradientStop x:Name="Colour5" Offset="0.8" />

     <GradientStop x:Name="Colour6" Offset="0.9" />

     <GradientStop Color="Black" Offset="1.0" />





Now the problem I have is retriving the ARGB values from a rectangle and passing them to the variable.  In the Form version I was able to use Dim VARIABLE as COLOR = OBJECT.BACKCOLOR but when I try this approach in the WPF version, basicall I get no love.  It's a syntax matter but I can't find the right method, I've tried VARIABLE=OBJECT.Fill and .FillProperty but still no luck.  All my VB experience has been Form based and I'm trying to come to grips with WPF so that I can port all my old apps/code to a form factor that is more polished.  The end goal is to have 6 colour swatches that control the colour variables and then 5 sliders that control the transition points of the final rectange which houses the final gradient.  The project also outputs each of the RGB values of the final gradient over a variable resolution to a 3rd party application.  This last piece was the easiest to code, I'm just stuck on the asthetics and form.  Any and all help is greatly appreciated.


when i click a row, the row is selected with a blue background.Is there a way to hide the selection ?

Thanks !


Hi ,

I'm trying to extract records from table inserted in last seven working days .

I'm unable to exclude Sunday and Saturday from this :

select * from tb_Name where dt >=DateAdd(dd, DateDiff(dd, 0, Getdate()), 0) and
 dt<DateAdd(dd, DateDiff(dd, 0, GetDate())-7, 0)

Any pointers would greatly  be valued and appreciated .

Thanks .


I saw so many people using the following expression in naming their file name.
"\\myPath\\myFolder\\myFile_" + (DT_WSTR, 4) YEAR( GETDATE()  )  + (DT_WSTR, 2)MONTH( GETDATE()  ) +  (DT_WSTR, 2) DAY( DATEADD("d", -SomeDays, GETDATE())  ) + ".txt"

I would like to point out an issue that I had found with this expression.
Let' say today is 03 September 2010, and SomeDays = -1. Then the result of the expression will be "\\myPath\\myFolder\\myFile_20100902.txt", which is correct.
How about if SomeDays = -3, the result will be "\\myPath\\myFolder\\myFile_20100931.txt". Can you spot the mistake?
That's right, the day is correct. BUT, the month is incorrect. It should be 08 instead of 09. And this could happen with the YEAR too if you're using DATEADD for month.

To avoid this issue, simply uses DATEADD(<date interval>, -Somedays, GETDATE() ), in YEAR, MONTH and DAY.

I hope this helps.




<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure