10 Answers, 1 is accepted
There are two possible solutions in removing the input RadWatermarkTextBox of the DatePicker control.
- Edit the Template of the control and remove the corresponding RadWatermarkTextBox.
- 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.
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.
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
Hello Nasko,
Thank you for your answer, but I tried with Dispatcher and datePickerTextBox is null yet.
I don't understand why.
Thank you.
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
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..
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
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.
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.
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