Home » WPFRSS

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" />
    </Style>

i hope this will help  you..

Mark it as answer if it helps you..

Thanks,

Bhavik

 

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..

Thanks,

Bhavik

<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" />
    </Style>
 

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

Hi,

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>
<toolkit:DatePickerTabIndex="4"x:Name="dtpDOB"Grid.Row="4"Grid.Column="1"Margin="2,0,48.656,0"VerticalAlignment="Center"/>

 

 

Answer 11

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

 

Answer 12

Hi,

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="HorizontalAlignment"Value="Left"/>
  <SetterProperty="VerticalAlignment"Value="Center"/>
  <SetterProperty="Margin"Value="5,0,0,0 "/>
  <SetterProperty="Foreground"Value="{TemplateBinding Foreground}"/>
</Style>

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

Hi,

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
 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter