using System.Collections.ObjectModel;
using System.Windows.Controls;
using System.Windows.Documents;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
public ObservableCollection<Log> Logs { get; set; } = new ObservableCollection<Log>();
private string _oldText = "";
private string _newText = "";
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
private void RichTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
_newText = new TextRange((e.Source as RichTextBox).Document.ContentStart, (e.Source as RichTextBox).Document.ContentEnd).Text;
Logs.Add(new Log { New = _newText, Old = _oldText });
_oldText = _newText;
}
public class Log
{
public string Old { get; set; }
public string New { get; set; }
}
}
}
<Window x:Class="WpfApp1.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"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<RichTextBox TextChanged="RichTextBox_TextChanged"/>
<DataGrid Grid.Row="1" ItemsSource="{Binding Logs}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="Было" Binding="{Binding Old}"/>
<DataGridTextColumn Width="*" Header="Стало" Binding="{Binding New}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
namespace TosterApp
{
class Program
{
static void Main(string[] args)
{
int input;
do Console.WriteLine("Enter number between 0 and 5:");
while (!int.TryParse(Console.ReadLine(), out input) || input <= 0 || input > 5);
Console.WriteLine($"You entered {input}");
}
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public List<Country> Countries { get; set; }
public List<City> Cities { get; set; }
public Form1()
{
InitializeComponent();
Countries = new List<Country>() { new Country { Name = "Russia" }, new Country { Name = "USA" } };
Cities = new List<City>() { new City { Name = "Moscow", Country = "Russia" }, new City { Name = "St. Petersburg", Country = "Russia" }, new City { Name = "New York", Country = "USA" }, new City { Name = "Florida", Country = "USA" } };
comboBox1.DataSource = Countries;
comboBox1.DisplayMember = "Name";
comboBox2.DisplayMember = "Name";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.DataSource = Cities.Where(x => x.Country == (comboBox1.SelectedValue as Country).Name).ToList();
}
}
public class Country
{
public string Name { get; set; }
}
public class City
{
public string Country { get; set; }
public string Name { get; set; }
}
}
<Grid DataContext="{Binding SelectedDaysObj}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" >
<CheckBox Content="Mo" IsChecked="{Binding Mo}"/>
<CheckBox Content="Tu" IsChecked="{Binding Tu}"/>
<CheckBox Content="We" IsChecked="{Binding We}"/>
<CheckBox Content="Th" IsChecked="{Binding Th}"/>
<CheckBox Content="Fr" IsChecked="{Binding Fr}"/>
<CheckBox Content="Sa" IsChecked="{Binding Sa}"/>
<CheckBox Content="Su" IsChecked="{Binding Su}"/>
</StackPanel>
<ListBox Grid.Column="1" ItemsSource="{Binding DaysOfWeek}"/>
</Grid>
public partial class MainWindow
{
public SelectedDays SelectedDaysObj { get; set; }
public MainWindow()
{
InitializeComponent();
DataContext = this;
SelectedDaysObj = new SelectedDays()
{
Mo = true, Fr = true, Sa = true
};
}
public class SelectedDays : INotifyPropertyChanged
{
public SelectedDays()
{
_daysOfWeek = new ObservableCollection<DayOfWeek>();
}
private bool _mo;
private bool _tu;
private bool _we;
private bool _th;
private bool _fr;
private bool _sa;
private bool _su;
private ObservableCollection<DayOfWeek> _daysOfWeek;
public bool Mo
{
get => _mo;
set
{
_mo = value;
OnPropertyChanged();
if (value)
{
if (!_daysOfWeek.Contains(DayOfWeek.Monday)) DaysOfWeek.Add(DayOfWeek.Monday);
}
else
{
if (_daysOfWeek.Contains(DayOfWeek.Monday)) DaysOfWeek.Remove(DayOfWeek.Monday);
}
}
}
public bool Tu
{
get => _tu;
set
{
_tu = value;
OnPropertyChanged();
if (value)
{
if (!_daysOfWeek.Contains(DayOfWeek.Tuesday)) DaysOfWeek.Add(DayOfWeek.Tuesday);
}
else
{
if (_daysOfWeek.Contains(DayOfWeek.Tuesday)) DaysOfWeek.Remove(DayOfWeek.Tuesday);
}
}
}
public bool We
{
get => _we;
set
{
_we = value;
OnPropertyChanged();
if (value)
{
if (!_daysOfWeek.Contains(DayOfWeek.Wednesday)) DaysOfWeek.Add(DayOfWeek.Wednesday);
}
else
{
if (_daysOfWeek.Contains(DayOfWeek.Wednesday)) DaysOfWeek.Remove(DayOfWeek.Wednesday);
}
}
}
public bool Th
{
get => _th;
set
{
_th = value;
OnPropertyChanged();
if (value)
{
if (!_daysOfWeek.Contains(DayOfWeek.Thursday)) DaysOfWeek.Add(DayOfWeek.Thursday);
}
else
{
if (_daysOfWeek.Contains(DayOfWeek.Thursday)) DaysOfWeek.Remove(DayOfWeek.Thursday);
}
}
}
public bool Fr
{
get => _fr;
set
{
_fr = value;
OnPropertyChanged();
if (value)
{
if (!_daysOfWeek.Contains(DayOfWeek.Friday)) DaysOfWeek.Add(DayOfWeek.Friday);
}
else
{
if (_daysOfWeek.Contains(DayOfWeek.Friday)) DaysOfWeek.Remove(DayOfWeek.Friday);
}
}
}
public bool Sa
{
get => _sa;
set
{
_sa = value;
OnPropertyChanged();
if (value)
{
if (!_daysOfWeek.Contains(DayOfWeek.Saturday)) DaysOfWeek.Add(DayOfWeek.Saturday);
}
else
{
if (_daysOfWeek.Contains(DayOfWeek.Saturday)) DaysOfWeek.Remove(DayOfWeek.Saturday);
}
}
}
public bool Su
{
get => _su;
set
{
_su = value;
OnPropertyChanged();
if (value)
{
if (!_daysOfWeek.Contains(DayOfWeek.Sunday)) DaysOfWeek.Add(DayOfWeek.Sunday);
}
else
{
if (_daysOfWeek.Contains(DayOfWeek.Sunday)) DaysOfWeek.Remove(DayOfWeek.Sunday);
}
}
}
public ObservableCollection<DayOfWeek> DaysOfWeek
{
get => _daysOfWeek;
set
{
_daysOfWeek = value;
OnPropertyChanged();
}
}
#region inpc
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A test = new A();
Console.WriteLine(test.B.testMethod());
Console.ReadLine();
}
}
class A
{
public class B
{
private string testB = "I'm test in class B";
public string testMethod ()
{
return testB;
}
}
}
}