Sie sind hier: WPF
Zurück zu: Oberflächen
Allgemein:
Vorlesungen
Labore
Sinnvolle Programme
Lineare Regression
GUI-Entwurfsarbeit
Single-Format
Design Pattern-Termine
Observer1
Bsp2
Json-Array
Json-Dialogelemente
Webtechnologien
Projetname | Description | Links |
XY-Graphics | User a usercontrol to show xy-Coordinates and lines. |
Video_XYGraphics.zip Video_XYGraphics.jpg Video_Graphic-Teil1.mp4 Video_Graphic-Teil2.mp4 Video_Graphic-Teil3.mp4 Video_Graphic-Teil4.mp4 |
Ableitung | Show a polynom in a xy-graphic. Use a Usercontrol-Element |
Ableitungen.zip Ableitungen.jpg Video_Graphic-Teil1.mp4 Video_Graphic-Teil2.mp4 Video_Graphic-Teil3.mp4 Video_Graphic-Teil4.mp4 |
La Grange Polynom |
Calculate a "La Grange Polynom" from coordinates. Show the complete polynom. |
LaGrange.zip LaGrangePolynom.pdf LaGrange.jpg Video_Graphic-Teil1.mp4 Video_Graphic-Teil2.mp4 Video_Graphic-Teil3.mp4 Video_Graphic-Teil4.mp4 |
IDW (inverse distance weighted) |
Given a some points. The IDW-Algorithmus calculate with a given point (double-click) the value. The coordinate can also read from a Shape-File (ArcView, QGis) |
IDW.zip IDW1.jpg IDW2.jpg Wikipedia Video_Graphic-Teil1.mp4 Video_Graphic-Teil2.mp4 Video_Graphic-Teil3.mp4 Video_Graphic-Teil4.mp4 |
CAD, MS-Paint |
It's a clone of MS-Paint. But the elements can be edit. You can export the draw to a DXF-File. |
CAD.zip CAD.jpg |
Charts |
Use the WPF graphic-tools. You have to copy two dll with the program: - System.Windows.Controls.DataVisualization.Toolkit.dll - WPFToolkit.dll In the zip-file there a many samples. The Picture show only one sample. |
Charts.zip Charts-1.jpg Charts-2.jpg Charts-3.jpg Charts-4.jpg Charts.mp4 |
Data Binding1/2/3 |
The three project show, how to user data-binding. With data-binding you not need to create an event-method to set the value to a another ui-elements. Example: <TextBox Height="35" HorizontalAlignment="Left" Margin="139,53,0,0" Name="textBox1" Text="{Binding ElementName=slider1, Path=Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="219" /> <Slider Height="23" Margin="52,124,68,0" Maximum="1000" Minimum="0" Name="slider1" TickFrequency="100" |
DataBinding.zip DataBinding.jpg |
AudioPlayer |
The AudioPlayer show in a tree the directories. You don't need to import the audio-files. You can select many input-directories. Input-Sources: mp3, wav, flac The image "directory.png" have to be in the directory. |
AudioPlayer.zip AudioPlayer.jpg Description_Audioplayer.pdf |
XML and JSon |
The project show how to load and save XML and JSon files. You need to use a netcode project. |
XML_JSon.zip XML_JSon1.jpg (netcore) XML_JSon2.jpg XML_JSon3.jpg |
MS Office |
The project show you, how one can save data in Excel or in Winword. It show, how to create a equation in Excel. It show, how to create a table In Winword. |
Office.zip Office1.jpg Office2.jpg Office3.jpg Office4.jpg |
Java IDE | The project show show to create a small Eclipse-Version. |
Video_JavaIDE.zip Video_JavaIDE1.jpg Video_JavaIDE2.jpg Video_JavaIDE3.jpg Java-IDE-Teil1.mp4 Java-IDE-Teil2.mp4 Java-IDE-Teil3.mp4 |
RibbonControl | This project show a sampls of the ribboncontrol. |
RibbonControl.zip RibbonControl1.jpg RibbonControl2.jpg RibbonControl3.jpg RibbonControl4.jpg RibbonControl5.jpg |
AccessDBConsole1 |
Here is a DBConsole with Access. The UI are with a RibbonControl. With the mousewheell you can changed the fontsize. The RibbonControl are not changed with the fontsize. |
Video_DBKonsole_Accces.zip Video_DBKonsole_Acccest1.jpg Video_DBKonsole_Acccest2.jpg DBConsole-Teil1.mp4 DBConsole-Teil2.mp4 |
AccessDBConsole2 |
Here is a DBConsole with Access. The UI are with a normal UI-Elements. With the mousewheell you can changed the fontsize. In this project changed also the icons. |
Video_DBKonsole_Access_Normal.zip Video_DBKonsole_Access_Normal1.jpg DBConsole-Teil1.mp4 DBConsole-Teil2.mp4 |
Firebird Konsole |
Here is a DBConsole with Firebird. The UI are with a normal UI-Elements. With the mousewheell you can changed the fontsize. In this project changed also the icons. |
FBKonsoleNormal.zip FBKonsoleNormal1.jpg DBConsole-Teil1.mp4 DBConsole-Teil2.mp4 |
SQLite Console |
Here is a DBConsole with Firebird. The UI are with a normal UI-Elements. With the mousewheell you can changed the fontsize. In this project changed also the icons. |
DBConsoleSQLite.zip DBConsoleSQLite1.jpg DBConsole-Teil1.mp4 DBConsole-Teil2.mp4 |
SyntaxHighlight |
The project use a Editor-UserControl to create an editor-application. It has four syntax-group: - java - cs - py - hmtl,hml,htm,css,php It has two colorarray: - lightmode - darkmode Threa is no color-dialog. Show my html-IDE. |
Video_Syntaxhighlight.zip Video_Syntaxhighlight-java.jpg Video_Syntaxhighlight-cs.jpg Video_Syntaxhighlight-php.jpg Video_Syntaxhighlight-python.jpg SyntaxHighlight.mp4 |
WebUpdate |
This project, better the three project, sow you, how you can create an web-update. 1. Project: Install_Main (the main-program) 2. Project: Install_SetWebVersion.exe (set the versionsnumber for the server) 3. Project: Install_WebInstaller.exe (load, unzip,copy) Also it show, how to update a database. |
WebUpdate.zip WebUpdate-InstallMain.jpg WebUpdate-Install_SetWebVersion.jpg WebUpdate-Install_WebInstaller.jpg webUpdate.mp4 |
DATAGRID | ||
DataGrid Access 1 |
This project show a datagrid applcation with: - Access database - Group and normal view - Window with a treee - Window with master/Details - Export 2 Excel - Export 2 Winword - with a DBConsole - with RibbonControl - the update to the database are directly |
Video_DataGrid_Access1.zip Video_DataGrid_Access1-Pict1.jpg Video_DataGrid_Access1-Pict2.jpg Video_DataGrid_Access1-Pict3.jpg Video_DataGrid_Access1-Pict4.jpg DataGrid-Teil1.mp4 |
DataGrid Access2 |
This project show a datagrid applcation with: - Access database - Group and normal view - Window with a treee - Window with master/Details - Export 2 Excel - Export 2 Winword - with a DBConsole - with RibbonControl - the update to the database are NOT directly - You can changed the values, but only after you close the window you get a questiion and save the changes. |
Video_DataGrid_Access2.zip Video_DataGrid_Access2-Pict1.jpg Video_DataGrid_Access2-Pict2.jpg Video_DataGrid_Access2-Pict3.jpg Video_DataGrid_Access2-Pict4.jpg DataGrid-Teil2.mp4 |
DataGrid Firebird |
This project show a datagrid applcation with: - Firebird database - Group and normal view - Window with a treee - Window with master/Details - Export 2 Excel - Export 2 Winword - with a DBConsole - with RibbonControl - the update to the database are NOT directly - You can changed the values, but only after you close the window you get a questiion and save the changes. |
Video_DataGrid_Firebird.zip Video_DataGrid_Firebird1.jpg Video_DataGrid_Firebird2.jpg Video_DataGrid_Firebird3.jpg Video_DataGrid_Firebird4.jpg DataGrid-Teil3.mp4 |
DataGrid SQLite |
This project show a datagrid applcation with: - SQLite database - Group and normal view - Window with a treee - Window with master/Details - Export 2 Excel - Export 2 Winword - with a DBConsole - with RibbonControl - the update to the database are NOT directly - You can changed the values, but only after you close the window you get a questiion and save the changes. |
Video_DataGrid_SQLite.zip Video_DataGrid_SQLite1.jpg Video_DataGrid_SQLite2.jpg Video_DataGrid_SQLite3.jpg Video_DataGrid_SQLite4.jpg DataGrid-Teil4.mp4 |
Kapitel |
Script (Eine Folie pro Seite) (Powerpoint) |
Script (Zwei Folien pro Seite) (Powerpoint) |
PDF-Datei (WinWord) |
Einleitung | Einleitung.pdf | Einleitung-2.pdf |
SdkXamlBrowser.exe SdkXamlBrowser.zip |
Layout | Layout.pdf | Layout-2.pdf |
Bild1.jpg Bild2.jpg Bild3.jpg Beispiele in der Vorlesung: beispiele_vorl.7z Vorgefertigte Beispiele in der Vorlesung: uebungen_vorl.7z |
Sprache C# | Sprache.pdf | Sprache-2.pdf | |
Dialog | dialog.pdf | dialog-2.pdf |
splitter.txt ueb31.txt |
Grafik | grafik.pdf | grafik-2.pdf |
grafik-2.pdf CAD-Beispiel: CAD_Loesung.7z |
Office1 | office.pdf | office-2.pdf | |
Threads | thread.pdf | thread-2.pdf | bsp_threads.7z |
DataBinding | databinding.pdf | databinding-2.pdf | |
Datenbanken | database.pdf | database-2.pdf |
Stichworte | Problem | Lösung |
Tab´s in Editoren | Tab´s in Editoren freischalten |
TextBox: editor.AcceptsReturn = true; editor.AcceptsTab = true; editor.Multiline = true; editor.ScrollBars = System.Windows.Forms.ScrollBars.Both; editor.TabStop = false; editor.WordWrap = false; editor.MaxLength = 327670; RichTextBox: richTextBox1.AcceptsTab = true; richTextBox1.Multiline = true; richTextBox1.TabStop = false; richTextBox1.WordWrap = false; richTextBox1.MaxLength = 327670; |
Konvertierung String nach Double Convert ToDouble |
Folgende Zahl x1 wird falsch konvertiert: Die Zahl x2 wird richtig konvertiert double x1, x2; String sStr1 = "123.456"; String sStr2 = "123,456"; x1 = Convert.ToDouble(sStr1); x2 = Convert.ToDouble(sStr2); Ursache: .net nimmt immer den Dezimaltrenner aus der Systemeinstellung |
double x1, x2; String sStr1 = "123.456"; String sStr2 = "123,456"; x1 = Convert.ToDouble(sStr1, System.Globalization.CultureInfo.InvariantCulture); x2 = Convert.ToDouble(sStr2, System.Globalization.CultureInfo.InvariantCulture); if (double.TryParse(textBox1.Text, System.Globalization. NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out value1) { } bei negativen Zahlen, speziell decimal: if (double.TryParse(textBox1.Text, System.Globalization. NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowLeadingSign, System.Globalization.CultureInfo.InvariantCulture, out value1) { } |
Konvertierung von Double nach String ToString |
Das Problem ist, das man den Punkt angibt, trotzdem ein Kommagesetzt wird (In Germany) |
Double d = 10.45678; string sd = d.ToString("##0.############"); Liefert 10,45678 string sd = d.ToString("##0.############", System.Globalization.CultureInfo.InvariantCulture); Liefert 10.45678 |
Hex nach int | Eine hexadezimale Zahl in einem Int umwandeln |
int value = 0; String input = "0x21"; // Eingangswert String sHex = input.Substring(2); // 0x abschneiden if (int.TryParse(sHex,System.Globalization.NumberStyles.HexNumber, __System.Globalization.CultureInfo.InvariantCulture, out value)) { ____cell.ToolTipText = value.ToString(); } |
instanceof | instance heisst in C# is, sonst ändert sich nix |
Beispiel: test_is.cs CQuadrat q1 = new CQuadrat(5); CRechteck r1 = new CRechteck(5, 3); Object obj = q1; if (obj is CQuadrat) { CQuadrat q = (CQuadrat)obj; } |
super | super heisst in C# this, sonst ändert sich nix |
public student() : this(0) { } public student(int Matrnr) { m_Matrnr = Matrnr; } |
Start Run Execute Aufruf |
Start eines Programms einer E-Mail-Adresse einer HTML-Seite |
using System.Diagnostics; // run Process Prog = new Process(); Prog.StartInfo.FileName = "mailto:mwilhelm@hs-harz.de"; Prog.StartInfo.Arguments = ""; Prog.Start(); Prog.Close(); Process Prog = new Process(); Prog.StartInfo.FileName = "http://mwilhelm.hs-harz.de"; Prog.StartInfo.Arguments = ""; Prog.Start(); Prog.Close(); Process Prog = new Process(); Prog.StartInfo.FileName = "notepad.exe"; Prog.StartInfo.Arguments = "C:\\Daten\\test.txt"; Prog.Start(); Prog.Close(); Process Prog = new Process(); Prog.StartInfo.FileName = "myprogram.exe"; Prog.StartInfo.Arguments = "C:\\Daten\\test.txt"; Prog.Start(); Prog.WaitForExit(); // wait for the process Prog.Close(); |
Start Run Execute Aufruf pipe stream |
Run a program and read the output. Then you can show the errortext in a window. |
String exeFile = @"c:\gcc-bsp\test.exe"; String compiler = @"c:\gcc\gcc.exe"; if (File.Exists(exeFile)) { __File.Delete(exeFile); } Process prog = new Process(); prog.StartInfo.UseShellExecute = false; //prog.StartInfo.RedirectStandardOutput = true; prog.StartInfo.RedirectStandardError = true; prog.StartInfo.FileName = compiler; prog.StartInfo.Arguments = @"c:\gcc-bsp\test.c" + " -o " + exeFile; prog.StartInfo.WorkingDirectory = @"c:\gcc\"; prog.Start(); //String errortext1 = prog.StandardOutput.ReadToEnd(); String errortext2 = prog.StandardError.ReadToEnd(); prog.WaitForExit(); // wait for the process prog.Close(); if (File.Exists(exeFile)) { __Process prog2 = new Process(); __prog2.StartInfo.FileName = exeFile; __prog2.StartInfo.Arguments = ""; __prog2.StartInfo.WorkingDirectory = Basis.getPath(exeFile); __prog2.Start(); __prog2.Close(); } else { __WError dialog = new WError(this, errortext2); __dialog.Show(); } |
Popupmenu, Contextmenu Mouse click Dynamisch erstellte Elemente |
Wie kann man bei mehreren automatisch erstellten Schaltern / Bilder / Componenten ein Popupmenü an der richtigen Stelle aufrufen |
Form1.cs Krocker.exe krocker.zip |
Random Zufallszahlen |
Erzeugen verschiedener Zufallszahlen |
Random rand = new Random(); int initValue = 10; Random rand = new Random(initValue); for (int j = 0; j < 6; j++) Console.Writeline(" {0,10} ", rand.Next(0,10)); rand.Next(von,bis) |
toString Format |
Ausgabe eines Double-Wertes mittels der Methode toString |
double x=1234.567; Edit.Text = x.ToString("#.##"); 1234,57 Edit.Text = x.ToString("00000"); 01235 (Rundung) Edit.Text = x.ToString("#"); 1235 (Rundung) Edit.Text = x.ToString("#,###"); 1.235 (Rundung, Tausender-Trennung) Edit.Text = x.ToString("#.##E+00"); 1.23E+03 (Rundung) |
GroupBox Button Checked UnChecked RadioButton |
In einer ToolStrip-Leiste sollen Schalter sich gegenseitig ausschalten, à la RadioButton |
// Gemeinsame Methode zum Löschen aller Schalter // dann setzen EINES Schalters private void setToolBarButtons(ToolStripButton BnActive) { Bn1.CheckState = System.Windows.Forms.CheckState.Unchecked; Bn2.CheckState = System.Windows.Forms.CheckState.Unchecked; BnActive.CheckState = System.Windows.Forms.CheckState.Checked; } private void Bn1_Click(object sender, EventArgs e) { setToolBarButtons(Bn1); } private void Bn2_Click(object sender, EventArgs e) { setToolBarButtons(Bn2); } |
Clipboard setzen holen |
Zugriff auf die Zwischenablage |
setzen: Clipboard.SetDataObject("hier ein Text"); holen: sStr = (string) ClipBoard.GetDataObject( typeof(string) ); |
OpenDialog | OpenDialog mit Startverzeichnis setzen | openFileDialog1.InitialDirectory = System.Environment.CurrentDirectory; |
ColorDialog | ColorDialog setzen, starten und die Farbe erhalten |
ColorDialog coldialog = new ColorDialog(); coldialog.FullOpen = true; coldialog.Color=PanelColor.BackColor; if (coldialog.ShowDialog() == DialogResult.OK) { PanelColor.BackColor = coldialog.Color; } |
foreach TabPages | Iteration über alle TabPages |
TextBox Editor2; int i=0; foreach (TabPage page in MainTab.TabPages) { i++; Editor2 = (TextBox)page.GetNextControl(page,true); Editor2.text = "Editor: "+i; } |
TreeNode im TreeView setzen | Wie kann man einen Knoten im TreeView setzen? | chkTree.SelectedNode = node ((c) by Beck) |
MVC-Modell | Fertiges Beispiel eines MDI-Programms mit selbst-erstelltem MVC-Modell. Verwendet wurde das Java-Modell mit Ableitung und Interface. Es kann also angepasst werden. | mdi_mvc.7z |
MDI-Fenster | Bestimmen des aktiven Elementes |
private ChildForm getActiceForm() { Form form = this.ActiveMdiChild; if (form==null) return null; else return (ChildForm) form; } |
System.Environment | Wichtige Elemente aus System.Environment |
System.Environment.CommandLine System.Environment.CurrentDirectory System.Environment.GetCommandLineArgs als String System.Environment.GetEnvironmentVariables System.Environment.GetLogicalDrives System.Environment.GetFolderPath System.Environment.MachineName System.Environment.OSVersion System.Environment.SpecialFolder System.Environment.SystemDirectory System.Environment.UserName System.Environment.ProcessorCount Anwendung: String path= Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); path.Replace("Desktop", "Downloads"); |
String[] args = System.Environment.GetCommandLineArgs(); for (int i = 1; i < args.Length; i++) { __String file = args[i]; __if (File.Exists(file)) { // now load __} } |
||
Explorer |
Bestimmen der Laufwerke Bestimmen der Verzeichnisse Bestimmen der Dateien |
String[] lws = System.Environment.GetLogicalDrives(); foreach (String lw in lws) { node = new TreeNode(lw, 3, 4); root.Nodes.Add(node); // Abfrage, ob CD eingelegt ? if (Directory.Exists(lw)) { string[] subdir = Directory.GetDirectories(lw); string[] files = Directory.GetFiles(lw); foreach (String file in files) { FileAttributes fileAttributes = File.GetAttributes(file); bool isReadOnly = (fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; } } // if } // foreach (String lw in lws) |
Einlesen von Text |
Welche Codierungen sind beim Einlesen möglich? (Encoding) |
String[] lines = File.ReadAllLines(filename, Encoding.GetEncoding(850)); String[] lines = File.ReadAllText(filename, System.Text.Encoding.ASCII); System.Text.Encoding.ASCII System.Text.Encoding.BigEndianUnicode System.Text.Encoding.Unicode System.Text.Encoding.UTF32 System.Text.Encoding.UTF7 // Delphi, DOS-Texte System.Text.Encoding.UTF8 Encoding.GetEncoding( 850): // Convert OemToChar Encoding.GetEncoding( 437): |
Kopieren und Ausschneiden à Explorer | Wie kann man die Shell-Copy/Paste-Funktionen einbinden |
Beispiel: FileOperationAPIWrapper.txt |
Lesen oder Schreiben eines Delphi-Records in C# | Definition eines Record in C# |
Man verwendet eine struct mit pack=1 Die festen Strings in Delphi können über ein Längenbyte und ein Array erfasst werden. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)] private struct MyRecord { public int hwnd; public double size; public bool gender; public byte stringlaenge; public char[] name; // Arrays werden mit einem Konstruktor initialisert public MyRecord(int anz) { hwnd = 0; size = 0; gender = true; stringlaenge = 0; name = new char[anz]; } } |
IBAN-Rechner | Ermitteln der IBan-Nummer | iban.txt |
dateierweiterung betriebssystem zuweisung programm fileextention operationssystem program |
Zuweisen einer Dateierweiterung zu einem Programm |
string ext = ".grf"; string title = "Grafikprogramm"; string extdescription = "Ein Grafikprogramm"; FileRegistrationHelper.SetFileAssociation(@"D:\CAD\CAD.exe", ext, title + "." + extdescription); FileRegistrationHelper.txt |
recursive filecopy without SHFILEOPSTRUCT | How can I copy files and directories without the Windows filecopy DLL? |
Source-code:
DirectoryCopy.txt Project: DirectoryCopy.zip Image: DirectoryCopy.png |
C# tempfile | How can I get a tempfile? |
public static String getTempFile() { __return System.IO.Path.GetTempFileName(); } |
Keywords | Description | Beschreibung | Solution |
WPF, Color, brush | How to set a color with code behind? | Wie setzt man eine Hintergrundfarbe mittels C#? |
byte red=255; byte green=255; byte blue=0; byte tranz=0; tTestBox.Foreground = new SolidColorBrush( Color.FromArgb(tranz, red, green, blue) ); tTestBox.Foreground = new SolidColorBrush( Color.Fromrgb(red, green, blue) ); |
WPF, OpenDialog, InitialDirectory | Openfiledialog with filter | OpenDialog mit Startverzeichnis setzen |
using Microsoft.Win32;// opendialog OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = System.Environment.CurrentDirectory; Complete Examples: opendialog.txt |
WPF, DrawText, Vertical | Using Drawtext in OnRender with horizontal and vertical | Wie benutzt man DrawText in OnRender mit vertikaler und horizontaler Ausrichtung |
int x = 100; int y = 100; formattedText = new FormattedText(text.Text, CultureInfo.GetCultureInfo("DE-de"), FlowDirection.LeftToRight, new Typeface("Verdana"), 24, Brushes.Red); // important angle with x and y int angle=-90; RotateTransform RT = new RotateTransform(angle, x, y); dc.PushTransform(RT); dc.DrawText(formattedText, new Point(x, y)); dc.Pop(); Complete Examples: drawText.txt |
WPF, Colordialog |
In WPF, there is no colordialog. Use this colordialog. It is modal and you can select a color with alpha-value |
Den Colordialog gibt es in WPF nicht. Also Nachprogrammieren und einsetzen. Oder man benutzt den WinForms-Color-Dialog. |
Execute: ColorDialog dialog = new ColorDialog(); dialog.setColor(colorLine); dialog.ShowDialog(); if (dialog.Retcode) { colorLine = Color.FromArgb(dialog.Alpha, dialog.Red, dialog.Green, dialog.Blue); bnLineColor.Background = new SolidColorBrush(colorLine); } Complete Examples: colordialog.txt Image: colordialog.png |
WPF, Grid row hidden row collapse |
set the height of a row in a grid to zero | Um eine Zeile zu löschen, setzt man die Zeile auf die Höhe null. |
XAML: <Grid x:Name="grid" > CS: public void setRow3Visible(bool visible) { __if (visible) { __grid.RowDefinitions[3].Height = new GridLength(0); _} _else { __grid.RowDefinitions[3].Height = new GridLength(1, GridUnitType.Star); _} } |
WPF, Spliterdialog à la Explorer vertical Spliter |
A Template with a Grid and a GridSplitter to simulate an Explorerdialog without any Buttons and any menues |
Ein Template mit einem Grid und einem GridSplitter, um ein Explorerdialog zu simulieren pures Grid |
Image: splitter1.png Complete Examples: SplitContainer1.7z Sample: <GridSplitter Name="splitterline" Grid.Column="0" Grid.Row="0" Width="3" Background="Red" /> Tip: No extra column |
WPF, Spliterdialog à la Explorer vertical Spliter |
A Template with a Grid and a GridSplitter to simulate an Explorerdialog with some Buttons and somemenues. It shows the Communication from Commands between Menues and Buttons |
Ein Template mit einem Grid und einem GridSplitter, um ein Explorerdialog zu simulieren Beinhaltet auch Menüs und Schalter. Es zeigt, wie die Kommunikation zwischen Menüs und Schaltern funktioniert (Commands) |
Image: splitter2.png Complete Examples: SplitContainer2.7z Sample: <GridSplitter Name="splitterline" Grid.Column="0" Grid.Row="0" Width="3" Background="Red" /> Tip: No extra column |
WPF, Horizontaler Splitter | An horozontal splitter is easy to create with a grid. But one must give the splitter an separate cell/row. | Ein horizontaler Splitter ist recht einfach mit einem Grid zu erstellen. Aber man muss den Splitter eine eigene Reihe geben. |
Sample: <GridSplitter Name="gridsplitter" Grid.Column="0" Grid.Row="1" Background="Red" Height="4" HorizontalAlignment="Stretch" /> Tip: One need a new column for the splitter |
WPF, vertical Splitter Position | How can I get and set the width of a splitter? | Wie kann man die Breite eines Splitter holen und setzen? |
get: ColumnDefinitionCollection cols = grid.ColumnDefinitions; double w = cols[0].ActualWidth; WriteRegistryInt(C_REG_ADR, "Splitterwidth", w); set: int w = ReadRegistryInt(C_REG_ADR, "splitterWidth"); if (w>50 && w<1000) { ColumnDefinitionCollection cols = grid.ColumnDefinitions; cols[0].Width = new GridLength(w); } |
WPF, horizontaler Splitter Position | How can I get and set the height of a splitter? | Wie kann man die Höhe eines Splitter holen und setzen? |
get: RowDefinitionCollection rows = splitContainer1.RowDefinitions; int h = (int)rows[1].ActualHeight; WriteRegistryInt(C_REG_ADR, "Splitterheight", h); set: int h = ReadRegistryInt(C_REG_ADR, "Splitterheight"); if (h>20 && h<700) { RowDefinitionCollection rows = splitContainer1.RowDefinitions; rows[1].Height = new GridLength(h); } |
WPF, Label, Border | How can I get a label with a border? | Wie kann man ein Label mit einem Rand (Strich umranden)? |
<Border CornerRadius="1" BorderBrush="Gray" BorderThickness="2" Margin="5"> __<Label Content="Daten verwalten" Foreground="Blue" /> </Border> |
WPF, Buttons, Image | How can I get a button with an image? | Wie erhält man einen Schalter mit ein Bild? |
<Button Grid.Column="7" Grid.Row="0" Name="bnFirst" Margin="20 0 0 0" ToolTip="Ersten Datensatz anzeigen" IsTabStop="False" Height="25" Width="25" Click="bnFirst_Click"> _<Image Source="/IGMStart;component/Images/first.png" Height="23" Width="23" /> </Button> |
WPF, Buttons, Label, Image | How can I get a button with a label and an image? | Wie erhält man einen Schalter mit einem Label und einem Bild? |
<Button Grid.Column="7" Grid.Row="0" Name="bnStart" Margin="20 0 0 0" IsTabStop="False" Height="25" Width="25" Click="bnStart_Click"> _<StackPanel> ___<Image Source="/IGMStart;component/Images/start.png" Height="23" Width="23" /> ___<Label Content="Starten der Prüfung" /> _</StackPanel> </Button> |
WPF, ListView edit items |
How edit a listview/gridview row ? | Wie kann man in einer ListView eine Zeile, ein Objekt editeren? |
MyClass cl; int i = listView1.SelectedIndex; if (i >= 0) { cl = (MyClass)listView1.Items[i]; // Dialog cl.attribut="new Value"; listView1.Items[i] = cl; listView1.Items.Refresh(); } |
WPF, ListView DoubleClick |
How can one implement a double-Click-Event in a listView ? | Wie kann man einen Double-Click-Event in eier ListView realisieren? |
private void Window_Loaded(object sender, RoutedEventArgs e) { listView1.AddHandler(Control.MouseDoubleClickEvent, new RoutedEventHandler(HandleDoubleClick)); } protected void HandleDoubleClick(object sender, RoutedEventArgs e) { mnEdit_Click(sender, e); } private void mnEdit_Click(object sender, RoutedEventArgs e) { // see also previous row } |
WPF tree selecteditem select node show selected node | How can I select a node and show the node in the tree? | Wie kann ich einen Knoten markieren und anzeigen? |
// selected treenode: tree.SelectedValuePath="root\abc\cde\edf"; TreeViewItem node = tree.selectedValue; node.IsSelected = true; node.BringIntoView(); tree.Focus(); |
WPF, DockPanel with C# |
How can I create a DockPanel and insert GUI-Elements? | Wie kann man einen DockPanel erzeugen und Elemente einfügen? |
Label label1 = new Label(); Label label2 = new Label(); TextBox editor = new TextBox(); WrapPanel wrapPanel = new WrapPanel(); wrapPanel.HorizontalAlignment = HorizontalAlignment.Center; wrapPanel.Children.Add( label1 ); wrapPanel.Children.Add( label2 ); DockPanel dockpanel = new DockPanel(); dockpanel.LastChildFill = true; // Important DockPanel.SetDock(wrapPanel, Dock.Bottom); DockPanel.SetDock(editor, Dock.Top); dockpanel.Children.Add(flowLayoutPanel1); dockpanel.Children.Add(editor); |
WPF, TextBox row column |
how can one get the actual row and column? | Wie kann man die aktuelle Zeile und Spalte erhalten? |
TextBox editor; int charIndex = editor.CaretIndex; int lineindex = (editor.GetLineIndexFromCharacterIndex(charIndex) + 1); int index_aktLine = editor.GetCharacterIndexFromLineIndex(lineindex - 1); lRowNr.Content = "Zl: " + lineindex; int columnCount = editor.SelectionStart - index_aktLine + 1; lColumnNr.Content = "Sp: " + columnCount; |
WPF, Label underline is not visible |
in a String ist an underline "_". The Label delete this. What can I do? |
Ein Label-Element löscht ein Underline "_". Abhilfe? |
Label lDatei; String sValue="bsp_001.txt"; lDatei.Content = sValue.Replace("_","__"); |
WPF Label Textbox Checkbox Radiobutton Margin Code behind | How can I set a margin with code behind? | Wie kann ich einen Rand in C# setzen? |
CheckBox chk = new CheckBox(); Thickness margin = chk.Margin; margin.Left = margin.Top = margin.Bottom = margin.Right = 5; chk.Margin = margin; |
WPF, TextBlock |
How can I create a TextBlock in XAML? | Wie gebe ich einen TextBlock in XAML ein? |
<TextBlock> __Hello! I am a TextBlock. __<LineBreak /> __Hello! I am a TextBlock. __<LineBreak /> </TextBlock> |
WPF, TextBlock |
How can I create a TextBlock in XAML with "Tabs" ? | Wie gebe ich einen TextBlock mit Einrückungen in XAML ein? |
<TextBlock> __<Run FontWeight="Bold" FontSize="14" Text="Ablauf:" /> __<LineBreak /> __<Run FontStyle="Italic" FontSize="12" Text=" • Installieren der Dos-Box" /> __<LineBreak /> __<Run TextDecorations="Underline" FontSize="12" Text=" • Anlegen eines Verzeichnisses (jeweils maximal 8 Buchstaben)" /> __<LineBreak /> __<Run FontSize="12" Text=" o Beispielsweise: D:\asm" /> __<LineBreak /> </TextBlock> |
WPF, TextBlock, Line break |
How can I create a line break? | Wie erzeuge ich einen Zeilenumbruch? | <LineBreak /> |
WPF, TextBlock, Code behind |
How can I create a TextBlock mit C#? | Wie erzeuge ich mit C# einen TextBlock? |
TextBlock txtBlock = new TextBlock(); txtBlock.Height = 30; txtBlock.Width = 250; txtBlock.Text = "I'm a TextBlock"; txtBlock.Foreground = new SolidColorBrush(Colors.Blue); myContainer.Children.Add(txtBlock); |
WPF, TextBox, remove Undo |
How can I delete/remove the undo-Stack in a TextBox? | Wi ekann ich den Undo-Stack löschen bzw. entfernen? |
You implement a loop: while (editor.Undo()) { } |
WPF, ListCheckBox |
In Winforms exists a ListCheckBox. Now in WPF also |
In Winforms gibt es eine ListCheckBox. Nun auch in WPF. |
ListCheckBox: Image: ListCheckBox1.jpg Quellcode: ListCheckBox1.txt Projekt-Quellcode: ListCheckBox1.zip |
WPF, ListCheckBox |
In Winforms exists a ListCheckBox. Now in WPF also This example put the selected items in a second Listbox . This is also possible for RadionButtons !! |
In Winforms gibt es eine ListCheckBox. Nun auch in WPF. Dieses Beispiel kopiert die markierten Elemente in eine rechte zusätzliche Listbox. Damit erhält man eine bessere Übersicht. |
ListCheckBox: Bild: ListCheckBox2.jpg Quellcode: ListCheckBox2.txt Projekt-Quellcode: ListCheckBox2.txt |
WPF, Timer |
how can one used a Timer? | Wie kann man einen Timer realisieren? |
using System.Windows.Threading; // Timer private void Window_Loaded(object sender, RoutedEventArgs e) { DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 1); // hour, min, sec // minmal one second, no millisecond /// with "FromMilliseconds" one can set millisecond dispatcherTimer.Interval = TimeSpan.FromMilliseconds(250); dispatcherTimer.Start(); } // window_Loaded private void dispatcherTimer_Tick(object sender, EventArgs e) { // action CommandManager.InvalidateRequerySuggested(); } |
WPF DataGrid Columnwidth C# |
How can I change the Column in a grid with C#? | Wie kann man eine Spalte in einem Grid mit C# ändern? |
<Grid Name="grid1" DockPanel.Dock="Top" > </Grid> ColumnDefinitionCollection cols = grid1.ColumnDefinitions; GridLength gl1; gl1 = new GridLength(200); cols[0].Width = gl1; |
WPF DataGrid Columnwidth C# |
How can I change the Column in a grid with C#? | Wie kann man eine Spalte in einem Grid mit C# ändern? |
datagrid.Columns[0].Width = 80; datagrid.Columns[1].Width = 100; |
WPF DataGrid select a row |
how can I scoll the datagrid rows? | wie kann ich eine Zeile in einem Datagrid ansteuern? |
1) Change the selectedIndex 2) scroll to View 3) Focus setzen Prev-Event: datagrid.SelectedIndex = datagrid.SelectedIndex - 1; datagrid.ScrollIntoView(datagrid.SelectedItem); datagrid.Focus(); navigatorbar_datagrid.txt |
WPF Datagrid background cell | how can I set the background of a cell ? | wie kann ich den Background einer Spalte/Zelle setzen ? |
Image: DatagridBackground.png DatagridBackground_MainWindow_xaml.txt DatagridBackground_MainWindow_cs.txt DatagridBackground_Model_Color.txt DatagridBackground_MyBkColorConverter1.txt DatagridBackground_MyBkColorConverter2.txt Project: DatagridBackground.zip |
WPF CardControl |
How can I create a CardLayout à la Java? |
Wie kann man einen Cardlayout à la Java erstellen? Die Elemente liegen alle übereinander. |
Solution: 1) create a TabControl 2) Insert the GUI-Elements 3) Set the Height to Zero 4) Delete Focus for the TabItem foreach (TabItem tabitem in tabControl1.Items) { tabitem.Height = 0; tabitem.Focusable = false; } Beispielprojekt: CardLayout.zip |
WPF TabControl mit CloseButton |
How can I create a TabControl mit a CloseButton in every TabItem? | Wie erhalte ich einen Schalter in jedem TabItem eines TabControls? |
Ablauf: Ableiten eines TabItems: MyTabItem Erzeugen eines UserControls Interface für das Schließen Interface in main implementieren Beim Erzeugen MyTabItem verwenden Beispielprojekt: TabControl_CloseButton.zip Bild: TabControl_CloseButton.jpg |
WPF TabControl ListView |
How can I create a ListView complete with C#? How can I add Events: SelectionChange DoubleClick HeaderClick (sort) |
Wie kann man eine ListView komplett mit C# programmieren? Wie kann man Events hinzufügen: SelectionChange DoubleClick HeaderClick (sort) |
ListView mit TabControl ListView komplett mit C# TabControl mit Schalter zum Beenden Quellcode: TabControl_ListView.zip |
WPF GroupBox |
How can I create a GroupBox? Also with an Image? |
Wie kann man eine GroupBox erstellen? Im Header soll auch ein Bild sein! |
GroupBox1 Einfache GroupBox mit ComboBox Projekt-Quellcode: GroupBox1.zip GroupBox: GroupBox1.txt GroupBox2 GroupBox mit ComboBox Die Überschift ist eine Zusammenfassung Image mit Label Projekt-Quellcode: GroupBox2.zip GroupBox: GroupBox2.txt |
WPF FileWatcher |
How can I create a FileWatcher with Code behind? |
Wie kann man manuell einen Filewatcher erzeugen? |
FileWatcher Erstellen eines Filewatchers Quellcode: filewatcher.txt |
WPF: set Cursor |
How can I set a Cursor Wait? | Wie kann man einen Pausenkursor setzen? |
Mouse.OverrideCursor = Cursors.Wait; try { // Action } finally { Mouse.OverrideCursor = null; } |
WPF webbrowser local file |
How can I set a file to an webbrowser? | Wie kann man einem Webbrowser eine lokale Datei zuweisen? | webbrowser.Navigate("file:///" + filename ); |
WPF Usercontrol | How can I insert a usercontrol? | Wie kann ich ein Usercontrol einfügen? |
XAML: 1) Link to the Project "MyProject" xmlns:local="clr-namespace:MyProject" 2) Insert the UI-Element <local:MyUserControl x:Name="myuserControl" /> |
WPF Focus TextBox SelectAll | What can I do, that with a tab the selected textbox ist fill selected? | Was muss man Einfügen, um bei einem Tabwechsel die Ziel-TextBox selektiert zu haben? | textbox_selectall |
WPF selectDirectory FolderBrowserDialog |
How can I select a directory? | Wie kann man ein Verzeichnis auswählen ? |
// externer Verweis eintragen // ProjektTree, Assemblies, Framework System.Windows.Forms private void bnSelectDirectory_Click(object sender, RoutedEventArgs e) { _System.Windows.Forms.FolderBrowserDialog dialog = new _System.Windows.Forms.FolderBrowserDialog(); _dialog.SelectedPath = System.Environment.CurrentDirectory; _System.Windows.Forms.DialogResult result = dialog.ShowDialog(); _if (result == System.Windows.Forms.DialogResult.OK) { ___aktion(dialog.SelectedPath); _} } |
WPF selectDirectory FolderBrowserDialog |
How can I use a FolderBrowserDialog in WPF? | Wie kann man ein FolderBrowserDialog, Auswahl eines Verzeichnisses, in WPF benutzen? |
the BEST way is to build an own Dialog: Properties: - save and restore the path in the registry - select an initial folder - show the selected node with node.BringIntoView() - userdirs: docs, music, pictures, videos, desktop Important: The four pictures must be in the programmfolders of the program Pictures: FolderBrowser1.png FolderBrowser2.png Project: FolderBrowser.zip |
WPF selectDirectory FolderBrowserDialog |
How can I use a FolderBrowserDialog in WPF AND show the files in the actual folder? |
Wie kann man ein FolderBrowserDialog, Auswahl eines Verzeichnisses, in WPF benutzen und wie kann man Dateien rehts neben dem Baum anzeigen? |
the BEST way is to build an own Dialog: Properties: - save and restore the path in the registry - select an initial folder - show the selected node with node.BringIntoView() - userdirs: docs, music, pictures, videos, desktop - show the files in a listview Important: The four pictures must be in the programmfolders of the program Pictures: FolderBrowser1.png FolderBrowser3.png Project: FolderBrowser2.zip |
WPF Popupmenu | How can I create a ContextMenu or a popupmenu? | Wie kann man ein ContextMenu oder ein Popupmenu erzeugen? | Contextmenu |
UAC User Access Control |
I'm a user-admin, but my program has no rights. How can I insert a UAC? |
As User-Admin one has not Admin-Control. You must insert a User Access Control in your application. Insert a UAC: Menu "Project -> Add new item -> Application Manifest file" (app.manifest) UAC1.png there are three values: - asInvoker - requireAdministrator - highestAvailable. Change line 19 from "asInvoker" to "requireAdministrator". app.mainfest.txt |
|
WPF PrimaryScreen set top, left |
How can I get and set the postion of a window? Especially with two screens. |
Wie kann man die Bildschirmposition des aktuellen Fensters speichern und restaurieren? |
In the attribs top, legt, width, height are the actual values. With two or more screens windows set the coordinates. But it can be negative (<0). C# save the resolution of the screen in four values: - VirtualScreenLeft - VirtualScreenTop - VirtualScreenWidth - VirtualScreenHeight Examples: One screen with one width 1900 pixel: One screen with one width 1000 pixel: In one position you get: - VirtualScreenLeft: 0 - VirtualScreenWidth: 2900 In other position you get: - VirtualScreenLeft: -1900 - VirtualScreenWidth: 1000 In third position you can get: - VirtualScreenLeft: -1000 - VirtualScreenWidth: 1900 So you save the position in the registry and compare the values with the four VirtualScreen-Values source |
Keywords | Description | Beschreibung | Solution |
WPF Office-Anbindung |
How can I control Office | Wie kann man Winword, Excel etc. ansteuern? |
Office1 Ansteuerung von Word, Excel, Excel-Formel Projekt-Quellcode: Office1.zip GroupBox: Office1.txt |
WPF Excel export slow |
The Export to Excel is VERY slow. How can I get it more efficient? |
Der Export nach Excel ist sehr langsam. Wie kann man den Export beschleunigen? |
1. solution: Export every cell Time: 158 sec 2. solution: Export every row Time: 53 sec 3. solution: Export every a block of cells and rows Time: 3 to 7 sec BIFF solution: Time: 0,04 sec ExcelSpeed.zip Quellcode |
WPF Excel export slow |
The Export to Excel is VERY slow. How can I get it more efficient? |
Der Export nach Excel ist sehr langsam. Wie kann man den Export beschleunigen? |
Complete Project with ProgressBar 1. solution: Export every cell Time: 91 sec 2. solution: Export every row Time: 16 sec 3. solution: Export every a block of cells and rows Time: 2,2 sec BIFF solution: Time: 0,01 sec Excel123.zip excel123.png |
Keywords | Description | Beschreibung | Solution |
WPF TabControl mit CloseButton |
How can I create a TabControl mit a CloseButton in every TabItem? | Wie erhalte ich einen Schalter in jedem TabItem eines TabControls? |
Ablauf: Ableiten eines TabItems: MyTabItem Erzeugen eines UserControls Interface für das Schließen Interface in main implementieren Beim Erzeugen MyTabItem verwenden Beispielprojekt: TabControl_CloseButton.zip Bild: TabControl_CloseButton.jpg |
WPF
TabControl mit CloseButton
Descroption:
How can I create a TabControl mit a CloseButton in every TabItem?
Beschreibung:
Wie erhalte ich einen Schalter in jedem TabItem eines TabControls?
Ablauf:
Ableiten eines TabItems: MyTabItem
Erzeugen eines UserControls
Interface für das Schließen
Interface in main implementieren
Beim Erzeugen MyTabItem verwenden
Beispielprojekt:
TabControl_CloseButton.zip
Bild:
TabControl_CloseButton.jpg
Keywords | Description | Beschreibung | Solution |
wpf progressbar thread backgroundworker |
How can I show a progressbar with a backgroundworker? A progressbar with a thread are not working! |
Wie kann ich eine Progressbar mit einen backgroundworker verknüpfen? Ein Progressbar funktioniert NICHT gut mit einem Tread! Am besten ist ein backgroundworker. |
1) XAML: insert a progressbar 2) CS: declare a global variable of a BackgroundWorker 3) CS: worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { ...} 4) CS: void dotheWork(object sender, DoWorkEventArgs e) { ...} progressbar1.txt Image: progressbar1.png Projekt: ProgressBar1.zip |
Charts a relativ simple to use.
Chartarten:
- Lines
- Bar (only horizontal!!!)
- Columns (only vertikal)
- Pie (Kuchen)
- Bubbles
- Area
- Scatter (Points)
Installation:
1) Download the library:
http://wpf.codeplex.com/releases/view/40535
Result: WPFToolkit.msi
2) Insert the DLL into the project:
1) View Projektmappen-Explorer:
Visual Studio 10
Item Verweise
Menuitem: Verweis hinzufügen
Register .NET
To sort by "Component name"
Find: "System.Windows.Controls.DataVisualization.Toolkit
Visual Studio 12
-References
-Add Reference
-Assemblies
- Extensions
Sort by "Name"
Find: "System.Windows.Controls.DataVisualization.ToolkitWhich files need my customer?
1) the exe-file
2) System.Windows.Controls.DataVisualization.Toolkit.dll
3) WPFToolkit.dll
All programms: chart-exe.zip
Keywords | Description | Beschreibung | Solution |
chart wpf liniseries | How to create a chart with lineSeries? | Wie erzeuge ich ein Linien-Diagramm? |
1) XAML: create a chart 2) CS: add a LinesSeries to the chart LinesSeries1.txt Image: chart_linie1.png Projekt: Chart_Linien1.zip |
chart wpf liniseries | How to create a chart with two lineSeries? | Wie erzeuge ich ein zwei Linien-Diagramme? |
1) XAML: create a chart with tow LinesSeries 2) CS: add two LinesSeries to the chart LinesSeries2.txt Image: chart_linie2.png Projekt: Chart_Linien2.zip |
chart wpf Dash Lines | How to create a dashedLine Style? | Wie erstellt man eine gestrichelte Linie? |
1) local Variable LineSeries ls2 = ((LineSeries)mcChart.Series[1]); 2) set the style ls2.PolylineStyle = GetDashedLineStyle(); 3) create the style Style GetDashedLineStyle() { _var style = new Style(typeof(Polyline)); _style.Setters.Add(new Setter(Shape.StrokeDashArrayProperty,_ _new DoubleCollection(new[] { 15.0, 5.0 }))); _return style; } I don't know, how to set a colour. |
chart wpf clipboard | How can I copy a chart to the clipboard? | Wie bekomme ich die Zeichnung in die Zwischenablage? | Chart2Clipboard.txt |
chart wpf pie | How can I create a chart of pieseries? | Wie erzeuge ich ein Kuchendiagramm? |
1) XAML: create a chart 2) CS: add a PieSeries to the chart PieSeries1.txt Image: chart_pie1.png Projekt: Chart_Kuchen1.zip |
chart wpf bar horizontal | How can I create a horizontal bar? | Wie erzeuge ich horizontale Bars? |
1) XAML: create a chart 2) CS: add a BarSeries to the chart BarSeries1.txt Image: chart_bars1.png Projekt: Chart_Bars1.zip |
chart wpf bar vertical columns |
How can I create one vertical bars? | Wie erzeuge ich eine Grafik mit vertikalen Bars? |
1) XAML: create a chart 2) CS: one BarSeries to the chart ColumnsSeries1.txt Note: If the x-coordinates a different, then the two bars shown sequentiell. If the x-coordinates a identical, then the two bars shown with two bars-series. Image: chart_columns1.png Projekt: Chart_Column1.zip |
chart wpf bar vertical columns |
How can I create two vertical bars? | Wie erzeuge ich zwei vertikale Bars-Serien? |
1) XAML: create a chart 2) CS: add two BarSeries to the chart ColumnsSeries2.txt Note: If the x-coordinates a different, then the two bars shown sequentiell. If the x-coordinates a identical, then the two bars shown with two bars-series. Image: chart_columns2.png Projekt: Chart_Column2.zip |
chart wpf bar vertical columns |
How can I create two bars and the bars are together? | Wie erzeuge ich zwei vertikale Bars, in dem die einzelnen Balken nebeneinander sind? |
1) XAML: create a chart 2) CS: add two BarSeries to the chart ColumnSeries3.txt Note: If the x-coordinates a different, then the two bars shown sequentiell. If the x-coordinates a identical, then the two bars shown with two bars-series. Image: chart_columns3.png Projekt: Chart_Columns3.zip |
chart wpf dynamic chart panel | How can I create a dynamic chart in a panel? | Wie erzeuge ich dynamische Diagramme in einem Panel? |
If you create a dynamic series and you try to insert the series into the chart, you receive an error. The problem are some null-attribs. I don't solve the problem, but I have a solution: Solution: 1) Insert a DockPanel as a container for the chart. 2) Create an usercontrol named "UserChart" 3) In the action_method insert the chart __UserChart userchart = new UserChart(); __userchart.mcChart.Title = "Titel"; __userchart.Background = Brushes.LightSkyBlue; 4) Next insert the series ColumnSeries4.txt Image: chart_columns4.png Projekt: Chart_Columns4.zip |
chart wpf chart dynamic series | How can I create a chart with a List? | Wie erzeuge ich ein Chart mit einer vorgegebenen Liste? |
1) create a Class "ModelChart" 2) create a List<ModelChart> 3) create a Window mit a constructor of List<ModelChart> 4) Now one must create an array with a KeyValuePair ____ KeyValuePair<String, decimal>[] valuesXY = ______new KeyValuePair<String, decimal>[chartListe.Count]; 5) put the values from the list in the array ____valuesXY[i] = new KeyValuePair<string, decimal>(chartListe[i].xValue, chartListe[i].yValue); 6) assign the ItemsSource ____ColumnSeries cs1 = ((ColumnSeries)mcChart.Series[0]); ____cs1.ItemsSource = valuesXY; textfile with the code sampleproject |
chart wpf bubbles | How can I create a bubbles chart? |
Wie erzeuge ich zwei Bubbles-Serien? Wie erzeuge ich zwei Kreis-Diagramme? |
1) XAML: create a chart 2) CS: add two BubblesSeries to the chart BubblesSeries.txt Note: One must create a private class with x/y/r Image: chart_bubbles.png Projekt: Chart_Bubbles.zip |
chart wpf area | How can I create a area chart? | Wie erzeuge ich ein Area-Chart? |
1) XAML: create a chart 2) CS: add two BubblesSeries to the chart AreaSeries1.txt Image: chart_area1.png Projekt: Chart_Area1.zip |
chart wpf scatter points | How can I create a scatter chart, a point chart? | Wie erzeuge ich ein Scatter oder Punkt-Chart? |
1) XAML: create a chart 2) CS: add two BubblesSeries to the chart ScatterSeries1.txt Image: chart_scatter_points1.png Projekt: Chart_Scatter1.zip |
Keywords | Description | Beschreibung | Solution |
select command | How to use a select command | Wie rufe ich mit einem Select-Befehl Daten aus der Datenbank? |
public DataTable selectDBS(string sSQL) { try { FbDataAdapter da = new FbDataAdapter(sSQL, _cnn); DataTable dt = new DataTable("RELATIONS"); da.Fill(dt); return dt; } catch (Exception e) { MessageBox.Show("Fehlerhafte SQL-Anweisung\r\n" + e.Message + "\r\n" + sSQL, "SQL-Fehler", MessageBoxButton.OK, MessageBoxImage.Error); return null; } } dbs.txt |
wrapper class | how can I create a wrapper class ? | wie kann ich die DataTable in eine Klasse umwandeln? |
1) You need a class "Department" with an interface "INotifyPropertyChanged" 2) each attrib must send an Change-Event 3) you need an array to save the objects (ObservableCollection<Department>) 4) Now, you only need to set the ItemsSource from a datagrid 5) datagrid.ItemsSource = dept_observerlist |
navigator in WPF? | how can I use a navigatorbar? | wie kann ich einen Navigator-Leiste einfügen? |
First Solution: a navigatorbar in each form 1) create a grid 2) insert the buttons with images 3) create the click-events Second Solution: a navigatorbar as Usercontrols 1) you create an usercontrol 2) insert the buttons with images 3) create the click-events in the usercontrols 4) create an interface "INavigatorbar" 5) the constructor get the parent "INavigatorbar" 6) in the click-events call the methods from "INavigatorbar" navigatorbar_xml.txt navigatorbar_cs.txt navigatorbar_interface.txt |
problems with the navigatorbar event | how can I scoll the datagrid rows? | wie kann ich eine Zeile in einem Datagrid ansteuern? |
1) Change the selectedIndex 2) scroll to View 3) Focus setzen Prev-Event: datagrid.SelectedIndex = datagrid.SelectedIndex - 1; datagrid.ScrollIntoView(datagrid.SelectedItem); datagrid.Focus(); navigatorbar_datagrid.txt |
ObservableCollection with delete items, datagrid | how can I "save" the delete-Object and recognize the new and modify Objects to modify the database? |
wie kann ich die gelöschten Objekte mit merken und die neuen und geänderten Objekte erkennen? Dann kann ich damit die Datenbank ändern. |
1) ModelObject has two new attribs 1a) bool newAttrib=true 1b) bool modifyAttrib=false 2) in the wrapper-Class (dataTable -> ObservableCollection ) change all attribt to false 2a) newAttrib=false 2b) modifyAttrib=false 3) in each setter-method set the modify-attrib 4) Now each new object has set the newAttrib 5) save the delete-object in a separate ObservableCollection 6) ask the user to save the changes (perhaps ;-) 7) save methods 7a) delete the items in the delete-list 7b) insert the new items 7c) update the modify items, that are not new datagrid_new_delete_modify.txt |
datagrid create manuel columns | how can I create manuel the columns from an class? | wie kann ich manuell die Spalten in einem Datagrid erzeugen |
Type myType = typeof(ModelEmployee); PropertyInfo[] propertyInfos = myType.GetProperties(); foreach (PropertyInfo propertyInfo in propertyInfos) { System.Diagnostics.Debug.WriteLine(propertyInfo.Name); DataGridTextColumn dataColumn = new DataGridTextColumn(); dataColumn.Header = propertyInfo.Name; Binding binding= new Binding(propertyInfo.Name); binding.Mode = BindingMode.TwoWay; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; dataColumn.Binding = binding; datagrid.Columns.Add(dataColumn); } datagrid_manual_column.txt |
sort in a datagrid | How can I sort two columns in a datagrid? | Wie kann ich zwei Spalten automatisch sortieren? |
ICollectionView collView = null; datagrid.ItemsSource = observerItems; collView = CollectionViewSource.GetDefaultView(datagrid.ItemsSource); collView.SortDescriptions.Add(new SortDescription("Lastname", ListSortDirection.Ascending)); collView.SortDescriptions.Add(new SortDescription("Firstname", ListSortDirection.Ascending)); datagrid_sort_column.txt |
datagrid computes by column |
I have a table with a "computes by" column. Samples: length=to-from yearsalary=monthsalary*12 name=Lastname+', '+firstname How can I updated the "computes by column"? |
Ich habe eine Entity-tabelle mit einer Spalte, die automatisch berechnet wird. In Firebird nennt man das "computes by" Beispiele: length=to-from yearsalary=monthsalary*12 name=Lastname+', '+firstname Wie kann man diese Spalte automatisch updated? nach dem Speichern und neuladen ist der Wert ja da, doch während des Editierens? |
The problem ist, that the Change-Event is fired with the previous-Value, so without any code, you see the last change. Solution: You must implemented a separate method to fire an update-Event datagrid_computed_by.txt // After the cell lost the focus, the yearsalary ist set to the new value private void datagrid_CellEditEnding(...) { if (col.Header.Equals("Monthsalary")) { DataGridRow row = e.Row; ModelEmployee empl = (ModelEmployee)row.Item; empl.updateYearsalary(); // important } In the class ModelEmployee: public void updateYearsalary() { NotifyPropertyChanged("Yearsalary"); System.Diagnostics.Debug.WriteLine("updateYearsalary: " + yearsalary); } |
datagrid with separate textbox |
I want a datagrid with an additional textbox. How ? |
Wie kann ich neben den Datagrid ein und mehrere Textbox anzeigen lassen? |
The textbox need two values: 1) the instance from the array 2) the name of the attrib Solution: you create a grid or any other layout with a textbox. the layoutcontainer get the instance with the datacontext. the textbox get the value swith the binding-option. XAML: <grid Name="gridDetails"> <TextBox Name="tFirstname" Text="{Binding Path=Firstname, UpdateSourceTrigger=PropertyChanged }" /> </grid> CS: gridDetails.DataContext = empl_items[0]; datagrid_additional_textbox.txt |
datagrid with separate checkbox | I want a column checkbox in a datagrid. | Wie kann ich ein bool'sches Attribut als Checkbox in einem Datagrid darstellen? |
<DataGridCheckBoxColumn Header="IsGoodWorker" Binding="{Binding Path=IsGoodWorker, UpdateSourceTrigger=PropertyChanged}" /> |
datagrid database "AllInOne" samples | Can I get an "AllInOne"-Sample"? | Gibt es ein "AllInOne"-Beispiel? |
SURE Only program: Database_AllInOne.zip Picture: Database_AllInOne1.png Projekt: Project_Database_AllInOne.zip main.xaml: MainWindow.xaml main.cs: MainWindow.xaml.cs |
datagrid database "AllInOne" samples with master/detail | Can I get an "AllInOne"-Sample" with two master/details-datagrids? | Gibt es ein "AllInOne"-Beispiel mit zwei Master/Detail-Datagrids? |
SURE Only program: Database_AllInOne2.zip Picture: Database_AllInOne2.png Projekt: Project_Database_AllInOne2.zip main.xaml: MainWindow.xaml main.cs: MainWindow.xaml.cs |
datagrid database "AllInOne" samples with DataGridComboBoxColumn and DataGridCheckBoxColumn | Can I get an "AllInOne"-Sample" with a DataGridComboBoxColumn and a DataGridCheckBoxColumn? | Gibt es ein "AllInOne"-Beispiel mit einer DataGridComboBoxColumn und einer DataGridCheckBoxColumn? |
SURE Solution with a column-Definition in XAML Only program: Database_AllInOne3.zip Picture: Database_AllInOne3.png Projekt: Project_Database_AllInOne3.zip main.xaml: MainWindow.xaml main.cs: MainWindow.xaml.cs |
datagrid database "AllInOne" samples with DataGridComboBoxColumn and a DataGridCheckBoxColumn Code behind | Can I get an "AllInOne"-Sample" with a DataGridComboBoxColumn and a DataGridCheckBoxColumn ? | Gibt es ein "AllInOne"-Beispiel mit einer DataGridComboBoxColumn und einer DataGridCheckBoxColumn ? |
SURE Solution with a column-Definition in CS !!! Only program: Database_AllInOne4.zip Picture: Database_AllInOne4.png Projekt: Project_Database_AllInOne4.zip main.xaml: MainWindow.xaml main.cs: MainWindow.xaml.cs |
You need five steps to use a DataGridComboBoxColumn:
1) an ObservableCollection with the list of the items for the combobox
ObservableCollection<ModelDept> dept_items = new ObservableCollection<ModelDept>();
2) Insert the items in the ComboBox
dept_items.Add(new ModelDept(1, "FINZ", "Finanzen")); // pindex, shortname, longname
3) Change the attrib in ModelEmployee
Change the attrib in ModelEmployee from DeptIndex, the key, to an complete Object from typ ModelDept
DeptIndex symbolize the Pindex in a dept
OLD: private long aindex;
NEW: private ModelDept dept;
You must scan the list of dept's to search the correct pindex and set the new attrib "dept"
4) Implement Equal (IMPORTANT)
This methode must override, because it is called to select the Combobox item in the datagrid from the start
public override bool Equals(object obj) {
_if (obj is ModelDept) {
__ModelDept dept = (ModelDept)obj;
__return shortName.Equals(dept.shortName);
_}
_else {
__return false; // this code prevents a cast-Error
_}
}
5) Define the ComboBox in XAML
<DataGridComboBoxColumn Header="Department" x:Name="cbDept" SelectedItemBinding="{Binding Dept}" />
in cs:
cbDept.ItemsSource = dept_items;
Projekt: Project_Database_AllInOne3.zip
main.xaml: MainWindow.xaml
main.cs: MainWindow.xaml.cs 5) Define the ComboBox only in CS
Now all columns are generated with cs-code:
// delete the underline ;-)
datagrid.AutoGenerateColumns = false;
Type myType = typeof(ModelEmployee);
PropertyInfo[] propertyInfos = myType.GetProperties();
foreach (PropertyInfo propertyInfo in propertyInfos) {
_System.Diagnostics.Debug.WriteLine(propertyInfo.Name);
_if (propertyInfo.Name.Equals("Dept")) {
__DataGridComboBoxColumn dataCB = new DataGridComboBoxColumn();
__dataCB.Header = "Department";
__Binding binding2 = new Binding("Dept");
__//binding2.Mode = BindingMode.TwoWay; // bringt probleme
__binding2.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
__dataCB.SelectedItemBinding = binding2;
__dataCB.ItemsSource = dept_items;
__datagrid.Columns.Add(dataCB);
_}
else {
__DataGridTextColumn dataColumn = new DataGridTextColumn();
__dataColumn.Header = propertyInfo.Name;
__Binding binding = new Binding(propertyInfo.Name);
__binding.Mode = BindingMode.TwoWay;
__binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
__dataColumn.Binding = binding;
__datagrid.Columns.Add(dataColumn);
_}
} // foreachProjekt: Project_Database_AllInOne4.zip
main.xaml: MainWindow.xaml
main.cs: MainWindow.xaml.cs
Das Programm zeigt den Zulauf in einem Schacht.
Der Winkel wird in gon, grad und mit Hilfe eines Sliders eingegeben.
Schacht.zip (Projekt)
Schacht.exe (Programm)
Bilder:
Schacht1.png
Schacht2.png
Windows Presentation Foundation
Thomas Claudius Huber
Galileo Computing
ISBN 978-3-8362-1538-1Pro WPF on C#2010
Matthew MacDonald
Apress-Verlag
ISBN 978-1-4302-7205-2
Window Presentation Foundation
Adam Nathan
SAMS-Verlag
ISBN 0-672-32891-7
Professional entwickeln mit Visual C# 2012
Grundlagen und Profiwissen
Matthias Geirhos
Galileo-Verlag
ISBN 978-3-8362-1954-9
Visual C# 2012
Grundlagen und Profiwissen
Doberanz, Gewinnus
Hanser-Verlag
ISBN 978-3-446-43439-4
WPF und XAML
Rainer Stropek, Karin Huber
entwickler.press
ISBN 978-3-939084-60-0
Professional entwickeln mit Visual C# 2012
Grundlagen und Profiwissen
Matthias Geirhos
Galileo-Verlag
ISBN 978-3-8362-1954-9
Visual C# 2012
Grundlagen und Profiwissen
Doberanz, Gewinnus
Hanser-Verlag
ISBN 978-3-446-43439-4Softwareentwicklung mit C#
Hanspeter Mössenböck
dpunkt.Verlag
ISBN 3-89864-406-5
Datenbank-Programmierung mit Visual C# 2008
Walter Doberanz, Thomas Gewinnus
Microsoft Press
ISBN 978-3-86645-421-7
Links
http://www.guidetocsharp.de
http://msdn.microsoft.com/de-de/library/kx37x362.aspx
http://www.java2s.com/Code/CSharp/CatalogCSharp.htm
Gehe zu: Export to Excel