Can you hide the Textbox?

11 posts, 1 answers
  1. Andrew
    Andrew avatar
    104 posts
    Member since:
    May 2008

    Posted 14 Mar 2013 Link to this post

    Is there a simple way to hide the textbox portion of the RadDatePicker control? I want the button and calendar functionality to remain as is but want to completely override the display method.

    Thanks.
  2. Answer
    Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 19 Mar 2013 Link to this post

    Hi Andrew,

    There are two possible solutions in removing the input RadWatermarkTextBox of the DatePicker control.
    1. Edit the Template of the control and remove the corresponding RadWatermarkTextBox.
    2. Use the Loaded event of the control, drill to the RadWatermarkTextBox and set its Visibility to Collapsed.

    The next code snippet shows how the Loaded event should look like in order to remove the input WatermarkTextBox:
    in xaml:

    <telerik:RadDatePicker Loaded="DatePicker_Loaded_1"/>

    and in the code behind:
    private void DatePicker_Loaded_1(object sender, RoutedEventArgs e)
    {
        var datePicker = sender as RadDatePicker;
        var datePickerTextBox = datePicker.ChildrenOfType<RadWatermarkTextBox>().FirstOrDefault() as RadWatermarkTextBox;
        datePickerTextBox.Visibility = System.Windows.Visibility.Collapsed;
    }

    Hope this is helpful.

    All the best,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Valentin
    Valentin avatar
    73 posts
    Member since:
    Mar 2016

    Posted 17 Nov in reply to Vladi Link to this post

    Hello Vladi,

     

    I'm working with telerik:RadDateTimePicker and I want to hide the Watermark input control, but with your code, datePickerTextBox is null. I changed the cast for sender  but the cast doesn't work. I searched differents controls like RadWatermarkTextBox but I didn't find it.

     

    Can you help me ? Thank you.

  5. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 21 Nov Link to this post

    Hi Valentin,

    The "datePickerTextBox" is still null because the RadWatermarkTextBox placed inside the DateTimePicker is not loaded completely. In order to get it as desired using the ChildrenOfType<T> method you need to call it inside a Dispatcher:
    private void RadDateTimePicker_Loaded(object sender, RoutedEventArgs e)
    {
        var datePicker = sender as RadDateTimePicker;
        Dispatcher.BeginInvoke(new Action(() =>
        {
            var datePickerTextBox = datePicker.ChildrenOfType<RadWatermarkTextBox>().FirstOrDefault() as RadWatermarkTextBox;
            datePickerTextBox.Visibility = System.Windows.Visibility.Collapsed;
        }));
    }

    Hope this helps.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Valentin
    Valentin avatar
    73 posts
    Member since:
    Mar 2016

    Posted 21 Nov in reply to Nasko Link to this post

    Hello Nasko,

     

    Thank you for your answer, but I tried with Dispatcher and datePickerTextBox is null yet.

     

    I don't understand why.

     

    Thank you.

  7. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 21 Nov Link to this post

    Hi Valentin,

    Please, check the attached sample that demonstrates how the proposed in my previous response approach works on our side - the "datePickerTextBox" is found as expected.

    I hope this will help you.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  8. Valentin
    Valentin avatar
    73 posts
    Member since:
    Mar 2016

    Posted 21 Nov in reply to Nasko Link to this post

    Ho god.... I'm not in the good Forum ........ I'm so so sorry !

    I'm working for WPF, not Silverlight.....

    Do you no if there is an equivalent post for WPF or if I need to create it ?

    I'm sorry again..

  9. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 21 Nov Link to this post

    Hi Valentin,

    We have checked the approach for WPF as well and it seems everything is working as expected without even using a Disptacher - the "datePickerTextBox" is found as expected. Please, check the attached WPF project that demonstrates that.

    It will be of great help if you modify the project in order to reproduce your scenario and demonstrate your issue and send it back to us - thus we could be to provide you with a prompt solution.

    Hope this helps.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  10. Valentin
    Valentin avatar
    73 posts
    Member since:
    Mar 2016

    Posted 21 Nov in reply to Nasko Link to this post

    Nasko,

     

    Thank you but it doesn't working too. My scenario is the same that your.

    My .Xaml :

    <telerik:RadDateTimePicker x:Name="dtpSelectJour" Margin="0,0,10,0" InputMode="DatePicker" DateSelectionMode="Day"
    DateTimeWatermarkContent="Sélectionner un jour de visualisation" IsEnabled="{Binding Path=IsChecked, ElementName=rdbtnSelectDay}" Loaded="dtpSelectJour_Loaded"/>

    It is in a StackPanel which is in a telerik:RadRibbonGroup which is in a telerik:RadRibbonTab which is in a telerik:RadRibbonView.

    And the Loaded method :

    private void dtpSelectJour_Loaded(object sender, RoutedEventArgs e)
    {
        var datePicker = sender as RadDateTimePicker;
        var datePickerTextBox = datePicker.ChildrenOfType<RadWatermarkTextBox>().FirstOrDefault() as RadWatermarkTextBox;
        datePickerTextBox.Visibility = System.Windows.Visibility.Collapsed;
    }

     

    The datePickerTextBox is always and always null. And I can't find the WatermarkTextBox.

     

    NOTA :

    It's stranlgy because I tried in an other project (like your because your project is not compatible with my VS 2010) and it working find.

     

    Thank you.

  11. Valentin
    Valentin avatar
    73 posts
    Member since:
    Mar 2016

    Posted 21 Nov Link to this post

    Nasko, I have a good new !

     

    I seen that my RadDateTimePicker is loaded 3 times ! I don't know why, but the 2 first times, datePickerTextBox is null, but not the third times, and so, the WatermarkTextBox is well collapsed.

    I seen too that the third loading is fired when i'm choose the correspondant RadRibbonTab (where there is my RadDateTimePicker). And this is the moment where my datePickerTextBox is find, and collapsed.

     

    So thank you very much for your help !

     

    Regards,

    Valentin.

  12. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 22 Nov Link to this post

    Hello Valentin,

    I am glad to here you were able to resolve your issue and now everything is working as expected for you. Basically the Loaded event gets invoked several times while the RibbonView is loading itself into the visual tree - because of that when the RibbonView is not completely loaded the RadDateTimePicker could not find the desired RadWatermarkTextBox.

    If you have any additional questions or concerns please, let us know.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
DevCraft banner