Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Window x:Class="WpfApplication2.MainWindow"
- 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:local="clr-namespace:WpfApplication2"
- mc:Ignorable="d"
- Title="MainWindow" Height="350" Width="525">
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="Auto" />
- <ColumnDefinition Width="5" />
- <ColumnDefinition />
- </Grid.ColumnDefinitions>
- <StackPanel Width="150" Grid.Column="0">
- <Button x:Name="button" Content="Load" Click="button_Click"/>
- <Label x:Name="label" Content="{Binding Linie}"/>
- <Label x:Name="label1" Content="{Binding Pola}"/>
- <Label x:Name="label2" Content="{Binding Litery}"/>
- </StackPanel>
- <GridSplitter x:Name="gridSplitter" Width="5" HorizontalAlignment="Stretch" Grid.Column="1"/>
- <DockPanel LastChildFill="True" Grid.Column="2" Margin="0,21,0,0">
- <WrapPanel x:Name="wrap" Margin="0,-19,0,0"/>
- <ListBox Margin="0,-19,0,0">
- <ListBox.ItemTemplate>
- <DataTemplate>
- <Label Content="{Binding Collection}"/>
- </DataTemplate>
- </ListBox.ItemTemplate>
- </ListBox>
- </DockPanel>
- </Grid>
- </Window>
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace WpfApplication2
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public string Linie
- {
- get { return (string)GetValue(LinieProperty); }
- set { SetValue(LinieProperty, value); }
- }
- public string Pola
- {
- get { return (string)GetValue(PolaProperty); }
- set { SetValue(PolaProperty, value); }
- }
- public string Litery
- {
- get { return (string)GetValue(LiteryProperty); }
- set { SetValue(LiteryProperty, value); }
- }
- public static readonly DependencyProperty LinieProperty = DependencyProperty.Register("Linie", typeof(string), typeof(MainWindow));
- public static readonly DependencyProperty PolaProperty = DependencyProperty.Register("Pola", typeof(string), typeof(MainWindow));
- public static readonly DependencyProperty LiteryProperty = DependencyProperty.Register("Litery", typeof(string), typeof(MainWindow));
- public ObservableCollection<string> collectionn = new ObservableCollection<string>();
- public ObservableCollection<string> Collection
- {
- get; set;
- }
- public MainWindow()
- {
- this.DataContext = this;
- InitializeComponent();
- }
- private void button_Click(object sender, RoutedEventArgs e)
- {
- OpenFileDialog theDialog = new OpenFileDialog();
- theDialog.Title = "Open Text File";
- theDialog.Filter = "TXT files|*.txt";
- theDialog.InitialDirectory = @"C:\";
- if (theDialog.ShowDialog() == true)
- {
- string filename = theDialog.FileName;
- //label3.Content = filename;
- string[] filelines = File.ReadAllLines(filename);
- //label.Content = filelines.Length.ToString() + " linii";
- int slowa = 0;
- int litery = 0;
- string[] labels = filelines[0].Split(',');
- for (int a = 0; a < filelines.Length; a++)
- {
- //if (a == 0)
- //{
- // for (int i = 0; i < filelines[a].Split(',').Length; i++)
- // {
- // labels[i] = filelines[a].Split(',')[i].ToString() + " ";
- // }
- // wrap.Children.Add(new TextBlock
- // {
- // Width = 999,
- // Text = labels[0],
- // Margin = new Thickness(5)
- // });
- //}
- //else
- //{
- String[] substrings = filelines[a].Split(',');
- slowa += substrings.Length;
- litery += filelines[a].Length;
- string text = "";
- for (int i = 0; i < filelines[a].Split(',').Length; i++)
- {
- text += labels[i] + ": " + filelines[a].Split(',')[i].ToString() + " ";
- }
- wrap.Children.Add(new TextBlock
- {
- Width = 80,
- Text = text,
- Margin = new Thickness(5)
- });
- //Collection.Add(text);
- //}
- }
- //label1.Content = slowa.ToString() + " słów";
- //label2.Content = litery.ToString() + " liter";
- Linie = filelines.Length.ToString() + " linii";
- Pola = slowa.ToString() + " słów";
- Litery = litery.ToString() + " liter";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement