public partial class MainWindow : Window
{
private int rows = 10;
private int columns = 10;
public MainWindow()
{
InitializeComponent();
configureGrid();
}
// Help Functions
private void configureGrid()
{
// Setting the number of rows and columns.
grid.Model.RowCount = rows;
grid.Model.ColumnCount = columns;
// Setting the width and height of the cells.
grid.Model.RowHeights.DefaultLineSize = 50;
grid.Model.ColumnWidths.DefaultLineSize = 50;
// Setting the background of the grid.
setGridBackgroundImage();
// Disabling column and row resizing.
IMouseController controller = grid.MouseControllerDispatcher.Find("ResizeRowsMouseController");
grid.MouseControllerDispatcher.Remove(controller);
controller = grid.MouseControllerDispatcher.Find("ResizeColumnsMouseController");
grid.MouseControllerDispatcher.Remove(controller);
// Configuring headers
configureHeaders();
grid.Model.QueryCellInfo += new Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventHandler(Model_QueryCellInfo);
}
private void setGridBackgroundImage()
{
CellSpanBackgroundInfo item = new CellSpanBackgroundInfo(1, 1, rows, columns);
item.Background = new ImageBrush(CreateBitMapImage("W:\\dhines\\douglas-jammer-overwatch\\DouglasJammerOverwatch\\bin\\Debug\\blueprint_pdf_to_jpg.jpg"));
grid.Model.CellSpanBackgrounds.Add(item);
}
private void configureHeaders()
{
grid.Model.RowHeights[0] = 25;
grid.Model.ColumnWidths[0] = 25;
grid.Model.HeaderStyle.Background = new SolidColorBrush(Colors.NavajoWhite);
}
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.Cell.RowIndex == 0 && e.Cell.ColumnIndex > 0)
{
e.Style.Text = GridRangeInfo.GetAlphaLabel(e.Cell.ColumnIndex);
e.Style.HorizontalAlignment = HorizontalAlignment.Center;
e.Style.VerticalAlignment = VerticalAlignment.Center;
}
else if (e.Cell.RowIndex > 0 && e.Cell.ColumnIndex == 0)
{
e.Style.Text = e.Cell.RowIndex.ToString();
e.Style.HorizontalAlignment = HorizontalAlignment.Center;
e.Style.VerticalAlignment = VerticalAlignment.Center;
}
}
private BitmapImage CreateBitMapImage(string imageName)
{
BitmapImage image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = new Uri(imageName);
image.EndInit();
return image;
}
}