Karnaugh-map/karnaugh-map/WPF-kmap/WPF-kmap/MainWindow.xaml.cs

57 lines
No EOL
1.4 KiB
C#

using System.Text;
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 WPF_kmap
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void boxOnClick(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
if (btn == null)
return;
int currentValue = 0;
if (btn.Tag != null)
{
currentValue = (int)btn.Tag;
}
else
{
if (btn.Content.ToString() == "X")
currentValue = -1;
else if (!int.TryParse(btn.Content.ToString(), out currentValue))
currentValue = 0;
}
int newValue;
if (currentValue == -1)
newValue = 0;
else if (currentValue == 0)
newValue = 1;
else
newValue = -1;
btn.Tag = newValue;
btn.Content = newValue == -1 ? "X" : newValue.ToString();
}
}
}