or
grid.Items.AddNew() creates a new row in the grid. I would now like to assign a value to cell[0] in the new row.
grid.Items[0] does not contain a method to access the cells.
How do I get to the cells?
I know that binding the grid to a datatable will be much easier, but I was hoping to access the cells directly, without having to create a table for the data first.
Thx!
NewGoalWindow view = new NewGoalWindow(); view.WindowStartupLocation = WindowStartupLocation.CenterOwner; view.Owner = WindowHelper.MainWindow; NewGoalViewModel model = new NewGoalViewModel(); model.RequestClose += delegate{ view.Close(); }; view.DataContext = model; view.ShowDialog();<ListBox x:Name="multipleItemsPresenter" ItemsSource="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <telerik:RadTimePicker Width="80" SelectedTime="{Binding Path=Time, Mode=TwoWay}"/> <TextBlock Margin="20,0,0,0" Text="{Binding Path=Time, Mode=OneWay}"> </StackPanel> </DataTemplate> </ListBox.ItemTemplate></ListBox>
< controls:PeriodControl From="{Binding Path=MarketDepthFrom, Mode=TwoWay}" To="{Binding Path=MarketDepthTo, Mode=TwoWay}" />
Here is XAML of our control:
<UserControl x:Class="LT.Desk.Controls.PeriodControl" xmlns:trans="clr-namespace:LT.Language;assembly=LT.Language" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:telerikRibbonBar="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.RibbonBar" xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"> <StackPanel Orientation="Horizontal"> <Grid Name="PeriodGroup"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBlock Text="{Binding Source={x:Static trans:LanguageManager.Instance}, Path=Dict[Period]}" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2,0,2,0"/> <telerik:RadComboBox HorizontalAlignment="Stretch" x:Name="PeriodTypeCombo" Margin="3,0,0,0" Grid.Row="0" Grid.Column="1" Height="15" Width="100" SelectionChanged="PeriodTypeCombo_SelectionChanged"> <telerik:RadComboBoxItem Content="{Binding Source={x:Static trans:LanguageManager.Instance}, Path=Dict[Day]}" /> <telerik:RadComboBoxItem Content="{Binding Source={x:Static trans:LanguageManager.Instance}, Path=Dict[Week]}" /> <telerik:RadComboBoxItem Content="{Binding Source={x:Static trans:LanguageManager.Instance}, Path=Dict[Month]}" /> <telerik:RadComboBoxItem Content="{Binding Source={x:Static trans:LanguageManager.Instance}, Path=Dict[Quarter]}" /> <telerik:RadComboBoxItem Content="{Binding Source={x:Static trans:LanguageManager.Instance}, Path=Dict[Year]}" /> </telerik:RadComboBox> <TextBlock Text="{Binding Source={x:Static trans:LanguageManager.Instance}, Path=Dict[From]}" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2,0,6,0"/> <telerik:RadDatePicker Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Width="100" Name="fromDP" SelectionChanged="fromDP_SelectionChanged"/> <TextBlock Text="{Binding Source={x:Static trans:LanguageManager.Instance}, Path=Dict[To]}" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2,0,6,0" /> <telerik:RadDatePicker Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" Width="100" Name="toDP" SelectionChanged="toDP_SelectionChanged" IsReadOnly="False" IsEnabled="True" /> </Grid> <Grid> <StackPanel Orientation="Horizontal"> <telerikRibbonBar:Separator Width="2"/> <telerikRibbonBar:RadRibbonButton Size="Large" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="Previous" Click="Prevoius_Click"> <StackPanel Name="PreviousButton" Orientation="Vertical"> <Image VerticalAlignment="Top" Height="38" Source="/LT.Desk;component/Resources/back-icon32.png"/> <TextBlock VerticalAlignment="Top" FontSize="12" HorizontalAlignment="Center" Margin="0,6,0,0" Text="{Binding Source={x:Static trans:LanguageManager.Instance}, Path=Dict[Previous]}"/> </StackPanel> </telerikRibbonBar:RadRibbonButton> <telerikRibbonBar:Separator Width="1"/> <telerikRibbonBar:RadRibbonButton Size="Large" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="Next" Click="Next_Click"> <StackPanel Name="NextButton" Orientation="Vertical"> <Image VerticalAlignment="Top" Height="38" HorizontalAlignment="Right" Source="/LT.Desk;component/Resources/next-icon32.png"/> <TextBlock VerticalAlignment="Top" FontSize="12" HorizontalAlignment="Center" Margin="0,6,0,0" Text="{Binding Source={x:Static trans:LanguageManager.Instance}, Path=Dict[Next]}"/> </StackPanel> </telerikRibbonBar:RadRibbonButton> <telerikRibbonBar:Separator Width="2"/> </StackPanel> </Grid> </StackPanel> </UserControl>
####################################################
And here is code behind for it:
public partial class PeriodControl { public DateTime? From { get { return (DateTime)GetValue(FromProperty); } set { SetValue(FromProperty,value); } } public DateTime? To { get { return (DateTime)GetValue(ToProperty); } set { SetValue(ToProperty, value); } } public PeriodTypeEnum PeriodType { get { return (PeriodTypeEnum)GetValue(PeriodTypeProperty); } set { SetValue(PeriodTypeProperty, value); } } public static DependencyProperty FromProperty = DependencyProperty.Register("From", typeof(DateTime?), typeof(PeriodControl)); public static DependencyProperty ToProperty = DependencyProperty.Register("To", typeof(DateTime?), typeof(PeriodControl)); public static DependencyProperty PeriodTypeProperty = DependencyProperty.Register("PeriodType", typeof(PeriodTypeEnum), typeof(PeriodControl)); public PeriodControl() { InitializeComponent(); fromDP.SelectedDate = DateTime.Today; toDP.SelectedDate = DateTime.Today; From = DateTime.Today; To = DateTime.Today; PeriodTypeCombo.SelectedIndex = 0; } private void fromDP_SelectionChanged(object sender, SelectionChangedEventArgs e)............ private void toDP_SelectionChanged(object sender, SelectionChangedEventArgs e)............. private void Next_Click(object sender, RoutedEventArgs e)................. private void PeriodTypeCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)............. }