Click here to Skip to main content
15,903,632 members
Home / Discussions / WPF
   

WPF

 
QuestionApply Css for Silverlight controls Pin
pavanip25-Jun-09 1:11
pavanip25-Jun-09 1:11 
AnswerRe: Apply Css for Silverlight controls Pin
Mark Salsbery29-Jun-09 9:31
Mark Salsbery29-Jun-09 9:31 
AnswerRe: Apply Css for Silverlight controls Pin
Jeremy Likness1-Jul-09 8:40
professionalJeremy Likness1-Jul-09 8:40 
AnswerRe: Apply Css for Silverlight controls Pin
PumbaPumba21-Feb-11 0:33
PumbaPumba21-Feb-11 0:33 
QuestionConditional XAML Pin
krishnan.s24-Jun-09 22:01
krishnan.s24-Jun-09 22:01 
AnswerRe: Conditional XAML Pin
ABitSmart24-Jun-09 22:10
ABitSmart24-Jun-09 22:10 
QuestionWPF Toolkit DatePicker/Calender issue Pin
bonkers12324-Jun-09 21:26
bonkers12324-Jun-09 21:26 
AnswerRe: WPF Toolkit DatePicker/Calender issue Pin
bonkers12324-Jun-09 22:58
bonkers12324-Jun-09 22:58 
ok, after A LOT of struggling, I managed to make a work around... but, it's not pretty !!! An easier solution would be much appreciated.

What I did, was the following:

<Controls:DatePicker Grid.Column="1" Grid.Row="6" SelectedDate="{Binding BirthDate}" ViewModels:EmployeeViewModel.DatePickerGotFocus="{Binding}">
            <Controls:DatePicker.CalendarStyle>
              <Style TargetType="Controls:Calendar">
                <Setter Property="Template">
                  <Setter.Value>
                    <ControlTemplate TargetType="Controls:Calendar">
                      <StackPanel HorizontalAlignment="Center" x:Name="Root">
                        <Controls:Calendar x:Name="Calendar" ViewModels:EmployeeViewModel.OnCalenderLoaded="{Binding}" SelectedDate="{Binding BirthDate}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                          <Controls:Calendar.CalendarDayButtonStyle>
                            <Style>
                              <Setter Property="Button.Height" Value="50"></Setter>
                              <Setter Property="Button.Width" Value="50"></Setter>
                              <Setter Property="Button.FontSize" Value="20"></Setter>
                            </Style>
                          </Controls:Calendar.CalendarDayButtonStyle>
                          <Controls:Calendar.CalendarButtonStyle>
                            <Style>
                              <Setter Property="Button.Height" Value="50"></Setter>
                              <Setter Property="Button.Width" Value="50"></Setter>
                              <Setter Property="Button.FontSize" Value="20"></Setter>
                            </Style>
                          </Controls:Calendar.CalendarButtonStyle>
                        </Controls:Calendar>
                      </StackPanel>
                    </ControlTemplate>
                  </Setter.Value>
                </Setter>
              </Style>
            </Controls:DatePicker.CalendarStyle>
          </Controls:DatePicker>




Then I made attached properties for the DatePicker and Calendar as follow:
private Calendar _calender;
    private DatePicker _datePicker;

    public static object GetDatePickerGotFocus(DependencyObject obj)
    {
      return (object)obj.GetValue(DatePickerGotFocusProperty);
    }

    public static void SetDatePickerGotFocus(DependencyObject obj, object value)
    {
      obj.SetValue(DatePickerGotFocusProperty, value);
    }

    // Using a DependencyProperty as the backing store for DatePickerGotFocus.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty DatePickerGotFocusProperty =
        DependencyProperty.RegisterAttached("DatePickerGotFocus", typeof(object), typeof(EmployeeViewModel), new UIPropertyMetadata(OnDatePickerGotFocus));

    private static void OnDatePickerGotFocus(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
      DatePicker datePicker = d as DatePicker; //d.GetValue(FocusEditProperty) as TextBox;
      EmployeeViewModel model = e.NewValue as EmployeeViewModel;
      if (datePicker != null && model != null)
      {
        model._datePicker = datePicker;
      }
    }


    public static object GetOnCalenderLoaded(DependencyObject obj)
    {
      return (object)obj.GetValue(OnCalenderLoadedProperty);
    }

    public static void SetOnCalenderLoaded(DependencyObject obj, object value)
    {
      obj.SetValue(OnCalenderLoadedProperty, value);
    }

    // Using a DependencyProperty as the backing store for OnCalenderLoaded.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty OnCalenderLoadedProperty =
        DependencyProperty.RegisterAttached("OnCalenderLoaded", typeof(object), typeof(EmployeeViewModel), new UIPropertyMetadata(OnCalenderLoaded));

    private static void OnCalenderLoaded(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
      Calendar calendar = d as Calendar; //d.GetValue(FocusEditProperty) as TextBox;
      EmployeeViewModel model = e.NewValue as EmployeeViewModel;
      if (calendar != null && model != null)
      {
        model._calender = calendar;
      }
    }


And then I set the visibility as follows:
public DateTime _birthDate;
public DateTime BirthDate
   {
     get { return _birthDate; }
     set
     {
       _birthDate = value;
       OnPropertyChanged("BirthDate");
       if (_calender != null)
       {
         _calender.Visibility = Visibility.Hidden;
         _datePicker.GotFocus += new RoutedEventHandler(_datePicker_GotFocus);
       }
     }
   }

   private void _datePicker_GotFocus(object sender, RoutedEventArgs e)
   {
     _calender.Visibility = Visibility.Visible;
     etc..

GeneralRe: WPF Toolkit DatePicker/Calender issue Pin
bonkers12325-Jun-09 1:40
bonkers12325-Jun-09 1:40 
GeneralRe: WPF Toolkit DatePicker/Calender issue Pin
Member 342384716-Nov-09 9:29
Member 342384716-Nov-09 9:29 
GeneralRe: WPF Toolkit DatePicker/Calender issue Pin
bonkers12323-Nov-09 0:20
bonkers12323-Nov-09 0:20 
GeneralRe: WPF Toolkit DatePicker/Calender issue Pin
Jimmy Carter23-Dec-09 9:57
Jimmy Carter23-Dec-09 9:57 
GeneralRe: WPF Toolkit DatePicker/Calender issue Pin
bonkers12312-Jan-10 2:07
bonkers12312-Jan-10 2:07 
GeneralRe: WPF Toolkit DatePicker/Calender issue Pin
tronix0127-Jan-11 22:54
tronix0127-Jan-11 22:54 
QuestionWPF Combobox not navigating to items on key press Pin
S Rajput24-Jun-09 20:22
S Rajput24-Jun-09 20:22 
AnswerRe: WPF Combobox not navigating to items on key press Pin
ABitSmart24-Jun-09 20:25
ABitSmart24-Jun-09 20:25 
GeneralRe: WPF Combobox not navigating to items on key press Pin
S Rajput24-Jun-09 20:29
S Rajput24-Jun-09 20:29 
GeneralRe: WPF Combobox not navigating to items on key press Pin
Christian Graus24-Jun-09 21:08
protectorChristian Graus24-Jun-09 21:08 
GeneralRe: WPF Combobox not navigating to items on key press Pin
S Rajput24-Jun-09 21:22
S Rajput24-Jun-09 21:22 
GeneralRe: WPF Combobox not navigating to items on key press Pin
ABitSmart24-Jun-09 21:37
ABitSmart24-Jun-09 21:37 
GeneralRe: WPF Combobox not navigating to items on key press Pin
ABitSmart24-Jun-09 21:34
ABitSmart24-Jun-09 21:34 
GeneralRe: WPF Combobox not navigating to items on key press Pin
S Rajput28-Jun-09 18:45
S Rajput28-Jun-09 18:45 
QuestionData binding from a List to a Grid Pin
fjparisIII24-Jun-09 15:39
fjparisIII24-Jun-09 15:39 
AnswerRe: Data binding from a List to a Grid Pin
Christian Graus24-Jun-09 16:24
protectorChristian Graus24-Jun-09 16:24 
GeneralRe: Data binding from a List to a Grid Pin
fjparisIII25-Jun-09 3:34
fjparisIII25-Jun-09 3:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.