Hi all,
I ahve Datagrid inside that DomainUpDown contol are place how to bind that data in silverlight
<sdk:DataGridTemplateColumn CanUserSort="True" Width="100" Header="Leverage" CanUserReorder="True" CanUserResize="False" > <sdk:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <toolkit:DomainUpDown VerticalAlignment="Center" Name="dupLeveagre" Width="100" ItemsSource="{Binding}" ValueMemberPath="LeverageValue" > <toolkit:DomainUpDown.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding LeverageValue}" /> </StackPanel> </DataTemplate> </toolkit:DomainUpDown.ItemTemplate> </toolkit:DomainUpDown> </DataTemplate> </sdk:DataGridTemplateColumn.CellEditingTemplate> </sdk:DataGridTemplateColumn> Please help me
Answer: 1
Hi,
In order to bind data to an DomainUpDown control in DataGrid Edit mode, you can use an ObservableCollection like this:
public class Customer { public int ID { get; set; } public String FirstName { get; set; } public String LastName { get; set; } public String Address { get; set; } public Customer(int id, String firstName, String lastName, String address) { this.ID = id; this.FirstName = firstName; this.LastName = lastName; this.Address = address; } } public class Customers : ObservableCollection<Customer> { public Customers() { Add(new Customer(1, "Michael", "Anderberg", "12 North Third Street, Apartment 45")); Add(new Customer(2, "Chris", "Ashton", "34 West Fifth Street, Apartment 67")); Add(new Customer(3, "Cassie", "Hicks", "56 East Seventh Street, Apartment 89")); Add(new Customer(4, "Guido", "Pica", "78 South Ninth Street, Apartment 10")); } } In the XAML, you can code like this:
<UserControl.Resources> <local:Customers x:Key="customers"></local:Customers> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <sdk:DataGrid AutoGenerateColumns="False" Height="300" HorizontalAlignment="Left" Margin="10,10,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="320" ItemsSource="{StaticResource customers}"> <sdk:DataGrid.Columns> <sdk:DataGridTemplateColumn Header="ID" IsReadOnly="True" > <sdk:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding ID}"></TextBlock> </DataTemplate> </sdk:DataGridTemplateColumn.CellTemplate> </sdk:DataGridTemplateColumn> <sdk:DataGridTemplateColumn CanUserSort="True" Width="100" Header="Leverage" CanUserReorder="True" CanUserResize="False"> <sdk:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <toolkit:DomainUpDown VerticalAlignment="Center" Name="dupLeveagre" Width="100" ValueMemberPath="FirstName" ItemsSource="{StaticResource customers}"> <toolkit:DomainUpDown.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding FirstName}" /> </DataTemplate> </toolkit:DomainUpDown.ItemTemplate> </toolkit:DomainUpDown> </DataTemplate> </sdk:DataGridTemplateColumn.CellEditingTemplate> <sdk:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding FirstName}" /> </DataTemplate> </sdk:DataGridTemplateColumn.CellTemplate> </sdk:DataGridTemplateColumn> </sdk:DataGrid.Columns> </sdk:DataGrid> </Grid> Note: For convenient, in my xaml code the DataGrid control and the DomainUpDown control have the same ItemsSource. But generally the ItemsSource property of an controls is different from its parent in real code. You can add another ObservableCollection in UserControl.Resources and specify it as DomainUpDown's ItemsSource as you wish.
Hope that will be helpful.
Best Regards,
Answer: 2
Hi All
I add another problem in DomainUpDown
how to get the value from the datagrid using ObservableCollection or any other way
ObservableCollection<InsertOrderDTO> obserlList = (ObservableCollection<InsertOrderDTO>)dgOrderRange.ItemsSource;
In obserlList doesn't have value which user select in the DomainUpDown.
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog