A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
c# wpf programm not running
noname
6
Reputation points
Hallo, ich habe ein kleines programm geschrieben und es stürzt teilweise einfach ab wegen einem Fehler in einer Zeile, den ich eigentlich schon ausgebessert habe
XML Reader (XML Dateien in bin->Debug)
public Form1()
{
InitializeComponent();
dataSet1.ReadXml("notes.xml");
bindingSource1.DataSource = dataSet1.Tables["Note"];
dataGridView1.AutoGenerateColumns = true;
}
private void readxml_Click(object sender, EventArgs e)
{
dataSet1.Clear();
dataSet1.ReadXml("notes.xml");
}
private void delete_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.SelectedRows){
dataGridView1.Rows.Remove(row);
}
dataSet1.WriteXml("notes.xml");
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
bindingSource1.EndEdit();
dataSet1.WriteXml("notes.xml");
}
XML Reader + Datenbank
public CDCatalog()
{
InitializeComponent();
sqlDataAdapter1.Fill(dataSet11);
}
private void delete_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
dataGridView1.Rows.Remove(row);
}
endEditUpdate();
}
private void update_Click(object sender, EventArgs e)
{
sqlDataAdapter1.Fill(dataSet11);
}
private void recreate_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "xml files |*.xml";
openFileDialog.ShowDialog();
foreach (DataRow dataRow in dataSet11.CD.Rows)
{
dataRow.Delete();
}
dataSet11.CD.ReadXml(openFileDialog.FileName);
endEditUpdate();
}
private void endEditUpdate()
{
bindingSource1.EndEdit();
sqlDataAdapter1.Update(dataSet11);
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
endEditUpdate();
}
WPF
MainWindow
Zu NavigationWindow ändern
Page 1
<Grid Margin="10,0,10,10">
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="300"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.Background>
<ImageBrush ImageSource="northern-lights-gedd43aef9_1280.jpg"/>
</Grid.Background>
<Label Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" FontFamily="Calibri light"
FontWeight="Bold" FontSize="38" Foreground="DeepPink">
Welcome
</Label>
<Button Grid.Column="0" Grid.Row="1" Margin="0,10,20,0" Width="125" Height="25" HorizontalAlignment="Right" Click="Button_Click">XML Reader</Button>
</Grid>
private void Button_Click(object sender, RoutedEventArgs e)
{
XMLReader reader = new XMLReader();
this.NavigationService.Navigate(reader);
}
Page 2
<Grid Margin="10,0,10,10">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="200"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.DataContext>
<XmlDataProvider x:Name ="dataProvider" Source="C:\Users\Lisa\Desktop\HTL\4BHIF\C#\WpfBsp\bin\Debug\notes.xml" XPath="Notes"/>
</Grid.DataContext>
<DataGrid Name="gridview" ItemsSource="{Binding XPath=Note}" AutoGenerateColumns="False" CellEditEnding="gridview_CellEditEnding">
<DataGrid.Columns>
<DataGridTextColumn Header="Author" Binding="{Binding XPath=Author,Mode=TwoWay}"/>
<DataGridTextColumn Header="Text" Binding="{Binding XPath=Text,Mode=TwoWay}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Page>
DLL Reflection
private void open_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "dll files (*.dll) |*.dll;";
dlg.ShowDialog();
if (dlg.FileName != null)
{
Assembly dllAssembly = Assembly.LoadFile(dlg.FileName);
TreeNode treeNode = new TreeNode();
treeNode.Text = dllAssembly.GetName().Name;
foreach(Type t in dllAssembly.GetTypes())
{
TreeNode typeNode = new TreeNode();
typeNode.Text = t.Name;
foreach(MemberInfo m in t.GetMembers())
{
typeNode.Nodes.Add(m.Name);
}
treeNode.Nodes.Add(typeNode);
}
dllTreeView.Nodes.Add(treeNode);
}
}
Developer technologies | Windows Presentation Foundation
Developer technologies | Windows Presentation Foundation
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Sign in to answer