Advertisement
Guest User

Untitled

a guest
May 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. <Window x:Class="WpfApplication2.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:local="clr-namespace:WpfApplication2"
  7. mc:Ignorable="d"
  8. Title="MainWindow" Height="350" Width="525">
  9. <Grid>
  10. <Grid.ColumnDefinitions>
  11. <ColumnDefinition Width="Auto" />
  12. <ColumnDefinition Width="5" />
  13. <ColumnDefinition />
  14. </Grid.ColumnDefinitions>
  15. <StackPanel Width="150" Grid.Column="0">
  16. <Button x:Name="button" Content="Load" Click="button_Click"/>
  17. <Label x:Name="label" Content="{Binding Linie}"/>
  18. <Label x:Name="label1" Content="{Binding Pola}"/>
  19. <Label x:Name="label2" Content="{Binding Litery}"/>
  20. </StackPanel>
  21. <GridSplitter x:Name="gridSplitter" Width="5" HorizontalAlignment="Stretch" Grid.Column="1"/>
  22. <DockPanel LastChildFill="True" Grid.Column="2" Margin="0,21,0,0">
  23. <WrapPanel x:Name="wrap" Margin="0,-19,0,0"/>
  24. <ListBox Margin="0,-19,0,0">
  25. <ListBox.ItemTemplate>
  26. <DataTemplate>
  27. <Label Content="{Binding Collection}"/>
  28. </DataTemplate>
  29. </ListBox.ItemTemplate>
  30. </ListBox>
  31. </DockPanel>
  32. </Grid>
  33. </Window>
  34.  
  35. using Microsoft.Win32;
  36. using System;
  37. using System.Collections.Generic;
  38. using System.Collections.ObjectModel;
  39. using System.IO;
  40. using System.Linq;
  41. using System.Text;
  42. using System.Threading.Tasks;
  43. using System.Windows;
  44. using System.Windows.Controls;
  45. using System.Windows.Data;
  46. using System.Windows.Documents;
  47. using System.Windows.Input;
  48. using System.Windows.Media;
  49. using System.Windows.Media.Imaging;
  50. using System.Windows.Navigation;
  51. using System.Windows.Shapes;
  52.  
  53. namespace WpfApplication2
  54. {
  55. /// <summary>
  56. /// Interaction logic for MainWindow.xaml
  57. /// </summary>
  58. public partial class MainWindow : Window
  59. {
  60. public string Linie
  61. {
  62. get { return (string)GetValue(LinieProperty); }
  63. set { SetValue(LinieProperty, value); }
  64. }
  65.  
  66. public string Pola
  67. {
  68. get { return (string)GetValue(PolaProperty); }
  69. set { SetValue(PolaProperty, value); }
  70. }
  71.  
  72. public string Litery
  73. {
  74. get { return (string)GetValue(LiteryProperty); }
  75. set { SetValue(LiteryProperty, value); }
  76. }
  77.  
  78. public static readonly DependencyProperty LinieProperty = DependencyProperty.Register("Linie", typeof(string), typeof(MainWindow));
  79. public static readonly DependencyProperty PolaProperty = DependencyProperty.Register("Pola", typeof(string), typeof(MainWindow));
  80. public static readonly DependencyProperty LiteryProperty = DependencyProperty.Register("Litery", typeof(string), typeof(MainWindow));
  81.  
  82. public ObservableCollection<string> collectionn = new ObservableCollection<string>();
  83.  
  84. public ObservableCollection<string> Collection
  85. {
  86. get; set;
  87. }
  88.  
  89.  
  90. public MainWindow()
  91. {
  92. this.DataContext = this;
  93. InitializeComponent();
  94. }
  95.  
  96. private void button_Click(object sender, RoutedEventArgs e)
  97. {
  98. OpenFileDialog theDialog = new OpenFileDialog();
  99. theDialog.Title = "Open Text File";
  100. theDialog.Filter = "TXT files|*.txt";
  101. theDialog.InitialDirectory = @"C:\";
  102. if (theDialog.ShowDialog() == true)
  103. {
  104. string filename = theDialog.FileName;
  105. //label3.Content = filename;
  106.  
  107. string[] filelines = File.ReadAllLines(filename);
  108. //label.Content = filelines.Length.ToString() + " linii";
  109.  
  110.  
  111. int slowa = 0;
  112. int litery = 0;
  113. string[] labels = filelines[0].Split(',');
  114.  
  115. for (int a = 0; a < filelines.Length; a++)
  116. {
  117. //if (a == 0)
  118. //{
  119. // for (int i = 0; i < filelines[a].Split(',').Length; i++)
  120. // {
  121. // labels[i] = filelines[a].Split(',')[i].ToString() + " ";
  122. // }
  123. // wrap.Children.Add(new TextBlock
  124. // {
  125. // Width = 999,
  126. // Text = labels[0],
  127. // Margin = new Thickness(5)
  128. // });
  129. //}
  130. //else
  131. //{
  132. String[] substrings = filelines[a].Split(',');
  133. slowa += substrings.Length;
  134. litery += filelines[a].Length;
  135.  
  136.  
  137. string text = "";
  138.  
  139. for (int i = 0; i < filelines[a].Split(',').Length; i++)
  140. {
  141. text += labels[i] + ": " + filelines[a].Split(',')[i].ToString() + " ";
  142. }
  143. wrap.Children.Add(new TextBlock
  144. {
  145. Width = 80,
  146. Text = text,
  147. Margin = new Thickness(5)
  148. });
  149. //Collection.Add(text);
  150. //}
  151.  
  152. }
  153.  
  154.  
  155. //label1.Content = slowa.ToString() + " słów";
  156. //label2.Content = litery.ToString() + " liter";
  157.  
  158. Linie = filelines.Length.ToString() + " linii";
  159. Pola = slowa.ToString() + " słów";
  160. Litery = litery.ToString() + " liter";
  161. }
  162. }
  163. }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement