Hallo,
ich habe einen DomainService über den ich Daten aus einer SQL-Datenbank lade und in einem GridVeiw anzeigen lasse.
Hier mein Code:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60:
| <navigation:Page x:Class="BusinessApplication1.Home" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" xmlns:service="clr-namespace:BusinessApplication1.Web.Services" xmlns:model="clr-namespace:BusinessApplication1.Web.Models" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" Style="{StaticResource PageStyle}">
<navigation:Page.Resources> <service:domainContext x:Name="domainContext"/> </navigation:Page.Resources> <Grid x:Name="LayoutRoot"> <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}" > <Grid x:Name="ContentGrid"> <Grid.RowDefinitions> <RowDefinition Height="0.1*"/> <RowDefinition Height="*"/> <RowDefinition Height="0.1*"/> <RowDefinition Height="0.1*"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="0.1*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="0.5*"/> <ColumnDefinition Width="0.5*"/> </Grid.ColumnDefinitions>
<TextBlock Text="Groups" FontSize="12" FontWeight="Black"/> <Button x:Name="buttonNewGroup" Content="New" Click="buttonNewGroup_Click" Grid.Column="1" Margin="1"/> <Button x:Name="buttondeleteGroup" Content="Delete" IsEnabled="{Binding ElementName=dataGridGroup, Path=SelectedIndex}" Click="buttondeleteGroup_Click" Grid.Column="2" Margin="1"/> </Grid> <TextBlock Grid.Column="2" Text="Modules" FontSize="12" FontWeight="Black"/> <TextBlock Grid.Row="3" Text="Questions" FontSize="12" FontWeight="Black"/> <TextBlock Name="dynamicTextBlock" Grid.Row="3" Grid.Column="2" Text="" FontSize="12" FontWeight="Black"/>
<sdk:DataGrid Grid.Row="1" AutoGenerateColumns="True" Height="200" Width="200" Name="dataGridGroup" ItemsSource="{Binding Data, ElementName=GroupDomainDataSource, Mode=TwoWay}"/> <sdk:DataGrid Grid.Row="1" Grid.Column="2" AutoGenerateColumns="False" Name="dataGrid2"/> <sdk:DataGrid Grid.Row="4" AutoGenerateColumns="False" Name="dataGrid3"/> <sdk:DataGrid Grid.Row="4" Grid.Column="2" AutoGenerateColumns="False" Name="dataGrid4"/>
<riaControls:DomainDataSource DomainContext="{Binding domainContext}" IsEnabled="True" AutoLoad="True" d:DesignData="{d:DesignInstance model:Group, CreateList=True}" LoadedData="GroupDomainDataSource_LoadedData" Name="GroupDomainDataSource" QueryName="GetGroups"/> </Grid> </ScrollViewer> </Grid> </navigation:Page> |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74:
| namespace BusinessApplication1 { using System.Linq; using System.Windows.Controls; using System.Windows.Navigation; using System.ServiceModel.DomainServices.Client; using BusinessApplication1.Web.Models; using BusinessApplication1.Web.Services;
public partial class Home : Page { public Home() { InitializeComponent(); this.Title = ApplicationStrings.HomePageTitle; }
protected override void OnNavigatedTo(NavigationEventArgs e) { }
private void GroupDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e) { System.Windows.MessageBox.Show("never reached?");
if (e.HasError) { System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK); e.MarkErrorAsHandled(); } }
private void buttonNewGroup_Click(object sender, System.Windows.RoutedEventArgs e) { DataForm dataForm = new DataForm() { CurrentItem = new Group(), AutoCommit = false };
dataForm.EditEnded += (s, args) => { if (args.EditAction == DataFormEditAction.Commit) { this.domainContext.Groups.Add((s as DataForm).CurrentItem as Group); this.GroupDomainDataSource.SubmitChanges(); } ((s as DataForm).Parent as ChildWindow).Close(); }; new ChildWindow() { Title = "Define new Group", Width = 400, Content = dataForm } .Show(); }
private void buttondeleteGroup_Click(object sender, System.Windows.RoutedEventArgs e) {
} } } |
Wenn das buttonNewGroup_Click - Ereignis aufgerufen wird, erstelle ich dynamisch ein ChildWindow mit einem DataForm. Soweit so gut. Bis vor kurzem konnte ich sogar neue Daten eintragen, die dann auch in der SQL-Tabelle gelandet sind. Leider muss ich irgendetwas verändert, haben, was jetzt zur entsprechenden Exception führt.
Ein zusätzliches Problem ist, dass mir im DataGrid (der Groups) weder die eigentlichen Daten, noch die Header (Spalten-Namen) angezeigt werden, obwohl dies im Designer der Fall ist.
Ich bin langsam echt verzweifelt, da das Ganze für mich nur schwer nachvollziehbar ist. Hoffe, dass ihr mir weiterhelfen könnt.