This is a migrated thread and some comments may be shown as answers.

RadDatePicker not binding current date

3 Answers 271 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Pranavi
Top achievements
Rank 1
Pranavi asked on 20 Aug 2013, 09:25 AM
hi 

I was added RadDatePicker to Footer with below code i want to display the default  Current date as "System.Date.Now";  but the date is not binding to that footer .

the same RadDatePicker i have in my form and i need to bind the same thing "System.Date.Now" it is binding but in footer it is not binding please help me


<TelerikGrid:GridViewDataColumn  Header="Qty1" MinWidth="100" Width="110"  TextAlignment="Right" DataMemberBinding="{Binding Qty1, Mode=TwoWay}" DataFormatString="{}{0:N2}">
                                                          <TelerikGrid:GridViewDataColumn.Footer>
                                                                <StackPanel Orientation="Vertical" Height="50" HorizontalAlignment="Left">
                                                                    <telerikInput:RadDatePicker x:Name="dt" HorizontalAlignment="Center"  SelectedValue="{Binding dat}" Margin="11,0,0,0" />
                                                                    <CheckBox  Height="16" Name="checkBox1"   IsChecked="{Binding Path=CurrentItem.InActive,Mode=TwoWay}" HorizontalAlignment="Center" />
                                                                </StackPanel>
                                                            </TelerikGrid:GridViewDataColumn.Footer>
                                                           </TelerikGrid:GridViewDataColumn>

3 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 20 Aug 2013, 03:22 PM
Hi Pranavi,

The used binding is not working because the GridViewDataColumn has different DataContext than the DataContext of the application. So one way to resolve this is to set the DataContext of the DatePicker to the same ViewModel that you use. Another way to go is to set it directly in XAML, you can achieve this by adding the following namespace:
xmlns:sys="clr-namespace:System;assembly=mscorlib"

And then you only need to set the SelectedValue as follows:
SelectedValue="{x:Static sys:DateTime.Now}"

Hope this helps.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Pranavi
Top achievements
Rank 1
answered on 21 Aug 2013, 06:57 AM
SelectedValue="{x:Static sys:DateTime.Now}"

the above statement is showing like  "Static is not supported in Silverlight project"
0
Kalin
Telerik team
answered on 21 Aug 2013, 02:33 PM
Hello Pranavi,

It works only in WPF applications. However here is another solution which uses the same DataContext as the GridView, just set the binding as the example below and should work as required:

SelectedValue="{Binding DataContext.dat, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=telerik:RadGridView}}"

I hope this will work for you.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
DatePicker
Asked by
Pranavi
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Pranavi
Top achievements
Rank 1
Share this question
or