private void CreateBindings() { // status Bar StatusLabel.SetBinding(ContentProperty, new Binding("Status") { Source = _statusBarModel, Mode = BindingMode.OneWay }); // settings BackgroundColorPicker.SetBinding(ColorPicker.SelectedColorProperty, new Binding("BackgroundColor") { Source = _settingsModel, Mode = BindingMode.TwoWay }); ForegroundColorPicker.SetBinding(ColorPicker.SelectedColorProperty, new Binding("ForegroundColor") { Source = _settingsModel, Mode = BindingMode.TwoWay }); ShowTransformationImageMenu.SetBinding(MenuItem.IsCheckedProperty, new Binding("ShowTransformationImage") { Source = _settingsModel, Mode = BindingMode.TwoWay }); ShowBlacklistedIconMenu.SetBinding(MenuItem.IsCheckedProperty, new Binding("ShowBlacklistedIcon") { Source = _settingsModel, Mode = BindingMode.TwoWay }); BlacklistedIconColorPicker.SetBinding(ColorPicker.SelectedColorProperty, new Binding("BlacklistedIconColor") { Source = _settingsModel, Mode = BindingMode.TwoWay }); }
private void InitializeControls(bool reversedView) { const double CoordinateSymbolSizeRatio = 0.5d; BoardGrid.Children.OfType <FrameworkElement>().DoForEach(obj => obj.DataContext = null); BoardGrid.ClearGrid(); RankSymbolGrid.ClearGrid(); FileSymbolGrid.ClearGrid(); Enumerable .Range(0, ChessConstants.RankCount) .DoForEach(i => BoardGrid.RowDefinitions.Add(new RowDefinition { Height = StarGridLength })); Enumerable .Range(0, ChessConstants.FileCount) .DoForEach(i => BoardGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = StarGridLength })); foreach (var square in ChessHelper.AllSquares) { var row = reversedView ? ChessConstants.RankRange.Lower + square.Rank : ChessConstants.RankRange.Upper - square.Rank; var column = reversedView ? ChessConstants.FileRange.Upper - square.File : ChessConstants.FileRange.Lower + square.File; var label = new Label { Margin = new Thickness(), Padding = new Thickness(), Tag = square, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 12, FontFamily = new FontFamily("Merida"), Width = 16, Height = 16 }; label.SetBinding(BackgroundProperty, new Binding(nameof(BoardSquareViewModel.Background))); label.SetBinding(ForegroundProperty, new Binding(nameof(BoardSquareViewModel.Foreground))); label.SetBinding(ContentProperty, new Binding(nameof(BoardSquareViewModel.Text))); label.MouseEnter += BoardSquare_MouseEnter; label.MouseLeave += BoardSquare_MouseLeave; label.MouseLeftButtonUp += BoardSquare_MouseLeftButtonUp; var border = new Border { Child = label, Margin = new Thickness(), Padding = new Thickness(), HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, DataContext = ViewModel.SquareViewModels[square], BorderThickness = new Thickness(1) }; border.SetValue(Grid.RowProperty, row); border.SetValue(Grid.ColumnProperty, column); border.SetBinding(Border.BorderBrushProperty, new Binding(nameof(BoardSquareViewModel.BorderBrush))); border.SetBinding(Border.BackgroundProperty, new Binding(nameof(BoardSquareViewModel.BorderBrush))); BoardGrid.Children.Add(border); } Enumerable .Range(0, ChessConstants.RankCount) .DoForEach(i => RankSymbolGrid.RowDefinitions.Add(new RowDefinition { Height = StarGridLength })); for (var rank = 0; rank < ChessConstants.RankCount; rank++) { var textBlock = new TextBlock { Margin = new Thickness(1), LayoutTransform = new ScaleTransform(CoordinateSymbolSizeRatio, CoordinateSymbolSizeRatio), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center, Text = (rank + 1).ToString(CultureInfo.InvariantCulture), Foreground = Brushes.CadetBlue }; var row = reversedView ? ChessConstants.RankRange.Lower + rank : ChessConstants.RankRange.Upper - rank; textBlock.SetValue(Grid.RowProperty, row); textBlock.SetValue(Grid.ColumnProperty, 0); RankSymbolGrid.Children.Add(textBlock); } Enumerable .Range(0, ChessConstants.FileCount) .DoForEach( i => FileSymbolGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = StarGridLength })); for (var file = 0; file < ChessConstants.FileCount; file++) { var textBlock = new TextBlock { Margin = new Thickness(1), LayoutTransform = new ScaleTransform(CoordinateSymbolSizeRatio, CoordinateSymbolSizeRatio), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center, Text = ((char)('a' + file)).ToString(CultureInfo.InvariantCulture), Foreground = Brushes.CadetBlue }; var column = reversedView ? ChessConstants.FileRange.Upper - file : ChessConstants.FileRange.Lower + file; textBlock.SetValue(Grid.RowProperty, 0); textBlock.SetValue(Grid.ColumnProperty, column); FileSymbolGrid.Children.Add(textBlock); } StatusLabel.SetBinding( ContentProperty, new Binding(nameof(GameWindowViewModel.CurrentGameBoard)) { Converter = StatusLabelTextConverter.Instance }); }