Bug on IsEnabled for DatePicker

Apr 14, 2010 at 8:37 AM

Hi,

I have a small problem with the datepicker and it's "isEnabled" property.

When I set the property in XAML this work perfectly.

                    <toolkit:DatePicker IsEnabled="False" Name='dp_birth' Height="23" HorizontalAlignment="Left" Margin="187,107,0,0" VerticalAlignment="Top" Width="120">                        
                        <toolkit:DatePicker.SelectedDate>
                            <Binding Path="date_birth" UpdateSourceTrigger="PropertyChanged">
                                <Binding.ValidationRules>
                                    <ExceptionValidationRule/>
                                </Binding.ValidationRules>
                            </Binding>
                        </toolkit:DatePicker.SelectedDate>
                    </toolkit:DatePicker>

But when I change it in C#, the "style" don't work : it's stay grey but we can edit it.

this.dp_birth.IsEnabled = true;
Apr 14, 2010 at 8:37 AM

Thanks in advance for your response.

Regards

May 3, 2010 at 9:17 AM

same issue for me

May 8, 2010 at 9:22 AM
D_Guidi wrote:

same issue for me

May be someone have a solution. I have found nothings

 

May 10, 2010 at 10:20 AM

Yip, same problem here and using Feb 10 release :(

Sep 2, 2010 at 9:00 AM

Same problem here using the Feb 2010 release, but I found a simple workaround.

You can add a <style> which highlights when a DatePicker control is disabled.
I've posted sample code here: 

http://stackoverflow.com/questions/2635385/wpf-datepicker-isenabled-property-not-changing-appearance/3625475#3625475

 

Feb 10, 2011 at 12:35 AM

      add this code  on OnIsEnabledChanged below OnVisualStatePropertyChanged(dp) and recompile the toolkit..this should work

  if (!dp.IsEnabled)
            {
                VisualStates.GoToState(dp, true, VisualStates.StateDisabled, VisualStates.StateNormal);
            }
            else
            {
                VisualStates.GoToState(dp, true, VisualStates.StateNormal);
            }

Aug 11, 2011 at 7:15 AM

 

 public class MyDatePicker : DatePicker
    {
        public MyDatePicker()
        {
            this.IsEnabledChanged += (o, e) => UpdateIsEnabledProperty(o as Control);
        }

        private static void UpdateIsEnabledProperty(Control ui)
        {
            if (ui == null)
                return;

            const string normal = "Normal";
            const string disabled = "Disabled";
            string name = ui.IsEnabled ? normal : disabled; 
            VisualStateManager.GoToState(ui, name , true);            
        }
}


Using this you can avoid recompilation, unfortunately in some cases this doesn't work