Добрый вечер. Код | private void Window_Loaded_1(object sender, RoutedEventArgs e) { DBWork.menuDataSet menuDataSet = ((DBWork.menuDataSet)(this.FindResource("menuDataSet"))); // Load data into the table images. You can modify this code as needed. DBWork.menuDataSetTableAdapters.imagesTableAdapter menuDataSetimagesTableAdapter = new DBWork.menuDataSetTableAdapters.imagesTableAdapter(); menuDataSetimagesTableAdapter.Fill(menuDataSet.images); System.Windows.Data.CollectionViewSource imagesViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("imagesViewSource"))); imagesViewSource.View.MoveCurrentToFirst(); // Load data into the table images. You can modify this code as needed. DBWork.menuDataSetTableAdapters.firstTableAdapter menuDataSetfirstTableAdapter = new DBWork.menuDataSetTableAdapters.firstTableAdapter(); menuDataSetfirstTableAdapter.Fill(menuDataSet.first); System.Windows.Data.CollectionViewSource firstViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("firstViewSource"))); firstViewSource.View.MoveCurrentToFirst(); }
|
Код | private void button1_Click(object sender, RoutedEventArgs e) { imagesDataGrid.ItemsSource = "{Binding Source={StaticResource imagesViewSource}}"; //тут должно быть что-то другое, но что(( }
|
Код | <Window x:Class="DBWork.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:DBWork" Loaded="Window_Loaded_1"> <Window.Resources> <my:menuDataSet x:Key="menuDataSet" /> <CollectionViewSource x:Key="imagesViewSource" Source="{Binding Path=images, Source={StaticResource menuDataSet}}" /> <CollectionViewSource x:Key="firstViewSource" Source="{Binding Path=first, Source={StaticResource menuDataSet}}" /> </Window.Resources> <Grid Height="321" Name="grid1" Width="515" > <Button Content="Button" Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="10,28,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<DataGrid AutoGenerateColumns="True" EnableRowVirtualization="True" Height="200" HorizontalAlignment="Left" ItemsSource="{Binding Source={StaticResource firstViewSource}}" Margin="3,-11,0,0" Name="firstDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="400"> </DataGrid> <DataGrid AutoGenerateColumns="True" EnableRowVirtualization="True" Grid.RowSpan="2" Height="200" HorizontalAlignment="Left" Margin="4,117,0,0" Name="imagesDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="400"> </DataGrid> </Grid> </Window>
|
В общем первый грид заполняется нормально, а для второго никак не получается правильно задать ItemsSource. Хотелось бы это сделать не через XAML, а в коде.
|