<Window x:Class="ApplicationWPF.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:ApplicationWPF"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid PreviewKeyUp="Grid_PreviewKeyUp">
<Label Content="Command1" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<ComboBox Name="comboBox1" HorizontalAlignment="Left" Margin="87,10,0,0" VerticalAlignment="Top" Width="120"/>
<Button Content="Применить" HorizontalAlignment="Left" Margin="212,10,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<TextBox Name="textBox1" HorizontalAlignment="Left" Height="254" Margin="10,56,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="277"/>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
namespace ApplicationWPF
{
public partial class MainWindow : Window
{
// https://docs.microsoft.com/ru-ru/dotnet/api/system.windows.forms.keys
private Dictionary<string, Key> keys = new Dictionary<string, Key>
{
{ "F1", Key.F1 },
{ "F2", Key.F2 }
};
private Key keyCommand1;
public MainWindow()
{
InitializeComponent();
foreach (KeyValuePair<string, Key> key in keys)
{
comboBox1.Items.Add(key.Key);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
keyCommand1 = keys[comboBox1.SelectedItem.ToString()];
}
private void Grid_PreviewKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == keyCommand1)
{
textBox1.Text += "Нажата клавиша " + e.Key.ToString() + " - Выполнение команды 1" + Environment.NewLine;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ApplicationWF
{
public partial class Form1 : Form
{
// https://docs.microsoft.com/ru-ru/dotnet/api/system.windows.forms.keys
private Dictionary<string, Keys> keys = new Dictionary<string, Keys>
{
{ "F1", Keys.F1 },
{ "F2", Keys.F2 }
};
private Keys keyCommand1;
public Form1()
{
InitializeComponent();
KeyPreview = true;
foreach (KeyValuePair<string, Keys> key in keys)
{
comboBox1.Items.Add(key.Key);
}
}
private void button1_Click(object sender, EventArgs e)
{
keyCommand1 = keys[comboBox1.SelectedItem.ToString()];
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == keyCommand1)
{
textBox1.Text += "Нажата клавиша " + e.KeyCode.ToString() + " - Выполнение команды 1" + Environment.NewLine;
}
}
}
}
List<int> arr = new List<int>();
foreach (char c in File.ReadAllText(@"путь к файлу"))
arr.Add((int)char.GetNumericValue(c));
/// <summary>
/// Изделие.
/// </summary>
class Product
{
private int _weight; // Вес изделия в килограммах.
private int _length; // Длина изделия в сантиметрах.
private string _material; // Материал изделия.
/// <summary>
/// Вес изделия в килограммах.
/// </summary>
public int Weight
{
get
{
return _weight;
}
set
{
_weight = value;
}
}
/// <summary>
/// Длина изделия в сантиметрах.
/// </summary>
public int Length
{
get
{
return _length;
}
set
{
_length = value;
}
}
/// <summary>
/// Длина изделия в сантиметрах.
/// </summary>
public string Material
{
get
{
return _material;
}
set
{
_material = value;
}
}
/// <summary>
/// Конструктор класса.
/// </summary>
public Product(int weight, int length, string material)
{
_weight = weight;
_length = length;
_material = material;
}
}
Dictionary<string, Product> products = new Dictionary<string, Product>();
products.Add("Брусок", new Product(2, 50, "Дерево"));
products.Add("Арматура", new Product(4, 200, "Сталь"));
products.Add("Гвоздь", new Product(1, 25, "Сталь"));
string materialArmature = products["Арматура"].Material;
int blockLength = products["Брусок"].Length;
<Window x:Class="WpfApplication3.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:WpfApplication3"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Image Name="image" HorizontalAlignment="Left" Height="282" Margin="18,18,0,0" VerticalAlignment="Top" Width="394" Source="{Binding MySource}"/>
<Button Name="button" Content="Button" HorizontalAlignment="Left" Margin="432,18,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
</Grid>
</Window>
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Windows;
namespace WpfApplication3
{
public partial class MainWindow : Window
{
public MyClass Class;
public MainWindow()
{
InitializeComponent();
Class = new MyClass();
image.DataContext = Class;
}
private void button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog myDialog = new OpenFileDialog();
if (myDialog.ShowDialog().Value)
Class.MySource = myDialog.FileName;
}
}
public class MyClass : INotifyPropertyChanged
{
private String mySource;
public String MySource
{
get
{
return mySource;
}
set
{
mySource = value;
OnPropertyChanged("MySource");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}