Grid Binding in Windows phone 7? - windows-phone-7

i am taking one grid having 3 rows and 3 columns .i want to bind the images to that grid actually images are added to grid but it is not added in correct way.i.e they are not place with in cells of grid .
How to bind 12 images correctly to cells of grid .i want all images are having same size and width placing properly in that grid.

I think my version is more clearly (3 col, rows auto):
ColumnDefinition coldef = new ColumnDefinition();
coldef.MinWidth = 135;
gridCat.ColumnDefinitions.Add(coldef);
coldef = new ColumnDefinition();
coldef.MinWidth = 135;
gridCat.ColumnDefinitions.Add(coldef);
coldef = new ColumnDefinition();
coldef.MinWidth = 135;
gridCat.ColumnDefinitions.Add(coldef);
RowDefinition rowdef = rowdef = new RowDefinition();
rowdef.MinHeight = 135;
gridCat.RowDefinitions.Add(rowdef);
for (int i = 0; i < App.CatViewModel.Items.Count; i++)
{
Image grid_image = new Image();
ImageSourceConverter c = new ImageSourceConverter();
grid_image.SetValue(Image.SourceProperty, c.ConvertFromString("img/touro.png"));
grid_image.SetValue(Image.WidthProperty, 128.0);
grid_image.SetValue(Image.HeightProperty, 128.0);
if ((i + 1) % 3 == 0)
{
rowdef = new RowDefinition();
rowdef.MinHeight = 135;
gridCat.RowDefinitions.Add(rowdef);
}
grid_image.SetValue(Grid.RowProperty, i/3);
grid_image.SetValue(Grid.ColumnProperty, i%3);
gridCat.Children.Add(grid_image);
}

<Grid HorizontalAlignment="left" Name="grid_main" Visibility="collapsed">
</Grid>
Here is the code which will arrange the 4 images in one row.
int j = 0;
int k = 0;
for (i = 1; i < 13; i++)
{
grid_image = new Image();
ColumnDefinition coldef = new ColumnDefinition();
coldef.Width = GridLength.Auto;
grid_main.ColumnDefinitions.Add(coldef);
// do this for each row
RowDefinition rowdef = new RowDefinition();
rowdef.Height = GridLength.Auto;
grid_main.RowDefinitions.Add(rowdef);
Grid.SetColumn(grid_image, 0);
Grid.SetRow(grid_image, 0);
if (j < 4)
{
grid_image.SetValue(Grid.RowProperty, k);
grid_image.SetValue(Grid.ColumnProperty, j++);
grid_main.Children.Add(grid_image);
}
else
{
j = 0; k = k + 1;
grid_image.SetValue(Grid.RowProperty, k);
grid_image.SetValue(Grid.ColumnProperty, j++);
grid_main.Children.Add(grid_image);
}
}

Related

Center a grid without spreading it out in Xamarin forms

I'm making a simple memory game, but for some reason I can't get the cards to not spread out like in the image. I put the cards in a grid that I put in the middle of a 3-column grid like this:
xaml:
<Grid x:Name="mainGrid">
<Image x:Name="bgImage" Aspect="AspectFill"/>
<Grid x:Name="innerGrid" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
</Grid>
cs:
Grid gr = new Grid
{
ColumnSpacing = 0,
RowSpacing = 0,
};
for (var i = 0; i < numRows; i++)
{
gr.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
}
for (var i = 0; i < numCols; i++)
{
gr.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
}
innerGrid.Children.Add(gr, 1,0);
var rowCount = 0;
var colCount = 0;
for (var i = 0; i < bricks.Count; i++)
{
Image img = new Image
{
Source = Globals.mediaUrl + bricks[i].img,
ClassId = bricks[i].img,
Margin = new Thickness(0, 0, 0, 0)
};
gr.Children.Add(img,colCount,rowCount);
colCount++;
if (colCount > numCols - 1)
{
colCount = 0;
rowCount++;
}
}
But for some reason I don't understand the cards spread out anyway like in this picture:
Can someone please help me with this
It's just a case of setting the "Aspect" property of your image to "Aspect.AspectFill".
I've taken your .xaml.cs code and added an example using a BowView
Grid gr = new Grid
{
ColumnSpacing = 0,
RowSpacing = 0,
};
var numRows = 3;
var numCols = 4;
for (var i = 0; i < numRows; i++)
{
gr.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
}
for (var i = 0; i < numCols; i++)
{
gr.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
}
innerGrid.Children.Add(gr, 1,0);
var rowCount = 0;
var colCount = 0;
var randomColors = new Color[]
{
Color.Aqua,
Color.Aquamarine,
Color.Azure,
Color.Beige,
Color.Bisque,
Color.Black,
Color.Blue,
Color.Brown,
Color.Chartreuse,
Color.Chocolate,
Color.Coral,
Color.Crimson,
};
for (var i = 0; i < 12; i++)
{
BoxView img = new BoxView()
{
BackgroundColor = randomColors[new Random().Next(0, randomColors.Length - 1)]
};
// Image img = new Image
// {
// Source = ImageSource.FromFile("xamarin.png"),
// Aspect = Aspect.AspectFill
// };
gr.Children.Add(img,colCount,rowCount);
colCount++;
if (colCount > numCols - 1)
{
colCount = 0;
rowCount++;
}
}
The end result, a bunch of colourful squares with no spacing between them:
Swapping out to an image (https://www.google.com/search?q=xamarin&tbm=isch&ved=2ahUKEwiIs5_o1pX2AhWKuSoKHYh9Ay8Q2-cCegQIABAA&oq=xamarin&gs_lcp=CgNpbWcQAzIECAAQQzIFCAAQgAQyBQgAEIAEMgUIABCABDIFCAAQgAQyBQgAEIAEMgUIABCABDIFCAAQgAQyBQgAEIAEMgUIABCABDoLCAAQgAQQsQMQgwE6CAgAEIAEELEDOgcIABCxAxBDUJgFWNoJYIYMaABwAHgAgAE-iAHJA5IBATiYAQCgAQGqAQtnd3Mtd2l6LWltZ8ABAQ&sclient=img&ei=rRQWYsioLIrzqgGI-434Ag&bih=764&biw=1477#imgrc=1Hifvt0AhVMSlM), and setting the aspect should yield the result you want.
Your layout code is fine, the issue is the aspect of the image itself.
This is so strange if I do it like that with a square image I get the result as in picture, so I don't get squares like you.
Grid gr = new Grid
{
ColumnSpacing = 2,
RowSpacing = 2,
};
for (var i = 0; i < numRows; i++)
{
gr.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
}
for (var i = 0; i < numCols; i++)
{
gr.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
}
var rowCount = 0;
var colCount = 0;
for (var i = 0; i < 12; i++)
{
Image img = new Image
{
Source = "https://pbs.twimg.com/profile_images/471641515756769282/RDXWoY7W_400x400.png",//Globals.mediaUrl + bricks[i].img,
ClassId = bricks[i].img,
Margin = new Thickness(0, 0, 0, 0),
Aspect = Aspect.AspectFill
};
gr.Children.Add(img,colCount,rowCount);
colCount++;
if (colCount > numCols - 1)
{
colCount = 0;
rowCount++;
}
}
innerGrid.Children.Add(gr, 1, 0);
I use FlexLayout with a binding to an ObservableCollection. This allows me some control over the size and shape of the images and display area, while also letting me take advantage of the flow properties of the FlexLayout.
I realize this is a different approach from what you were doing, but I hope you can take some value from this approach too.
xaml page:
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XFGrid_Test.BindablePage">
<ContentPage.Content>
<StackLayout VerticalOptions="Start">
<FlexLayout BindableLayout.ItemsSource="{Binding Images}"
Wrap="Wrap"
Direction="Row"
JustifyContent="Center"
AlignItems="Center"
AlignContent="Center"
x:Name="flexLayout">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Image ClassId="{Binding ImageCode}" Source="{Binding ImageSrc}" WidthRequest="{Binding ImageWidth}" HeightRequest="{Binding ImageHeight}" Margin="2" >
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" NumberOfTapsRequired="1"></TapGestureRecognizer>
</Image.GestureRecognizers>
</Image>
</DataTemplate>
</BindableLayout.ItemTemplate>
<BindableLayout.EmptyView>
<Label Text="Nothing here."></Label>
</BindableLayout.EmptyView>
</FlexLayout>
</StackLayout>
</ContentPage.Content>
xaml.cs:
public ObservableCollection<ImageModel> Images { get; set; }
int HorizontalMargin { get; set; }
int VerticalMargin { get; set; }
int VerticalAdjustment { get; set; } //adjusts for navigation and info bar
int numberOfImages = 25;
int numColumns = 6;
int MaxImageWidth;
int MaxImageHeight;
int ImageGap = 1;
public BindablePage()
{
InitializeComponent();
Images = new ObservableCollection<ImageModel>();
//Adjust the vertical display area to account for on-screen controls, etc.
//This needs refinement - or rethinking.
VerticalAdjustment = 100;
//Get the device display size (uses Xamarin.Essentials)
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
//Available horizantal screen space - x dimension
var xWidth = mainDisplayInfo.Width / mainDisplayInfo.Density;
//Available vertical screen space - y dimension
var yHeight = (mainDisplayInfo.Height / mainDisplayInfo.Density) - VerticalAdjustment;
//Determine the MaxImageWidth of the image to fit horizontally
//based on the number of rows desired and the available horizontal screen space
var numHorizontalGaps = numColumns * 2 - 1;
MaxImageWidth = (int)Math.Round(xWidth / numColumns, MidpointRounding.AwayFromZero) - numHorizontalGaps * ImageGap;
//Determine Number of image rows to fit vertically based on fixed number of columns and number of images
var nRows = numberOfImages / numColumns;
if (numberOfImages % numColumns > 0)
nRows++;
var numVerticalGaps = nRows * 2 - 1;
MaxImageHeight = (int)Math.Round(yHeight / nRows, MidpointRounding.AwayFromZero) - numVerticalGaps * ImageGap;
//Choose the dimension that is smaller (because it must fit).
var Dimension = Math.Min(MaxImageHeight, MaxImageWidth);
//Determine the left and right margins
HorizontalMargin = (int)Math.Round((xWidth - (((numColumns + 1) * Dimension) + (numColumns - 1) * ImageGap)), MidpointRounding.AwayFromZero) / 2;
//Determine the top and bottom margins - this will center top to bottom (set to zero for top alignment)
VerticalMargin = (int)Math.Round((yHeight - ((nRows) * Dimension) + (nRows - 1) * ImageGap), MidpointRounding.AwayFromZero) / 2;
//VerticalMargin = 0;
//Set the margins of the FlexLayout named "flexLayout"
flexLayout.Margin = new Thickness(HorizontalMargin, VerticalMargin);
//Load up the ObservableCollection
for (var i = 0; i < numberOfImages; i++)
{
ImageModel img = new ImageModel
{
ImageID = i,
ImageSrc = "https://pbs.twimg.com/profile_images/471641515756769282/RDXWoY7W_400x400.png",//Globals.mediaUrl + bricks[i].img,
ImageCode = i.ToString(),
ImageHeight = Dimension, //Height and Width shouild be equal
ImageWidth = Dimension,
ImageName = i.ToString(),
};
Images.Add(img);
}
BindingContext = this;
}
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
//Handle the tap
}
ImageModel class:
public class ImageModel
{
public int ImageID { get; set; }
public string ImageName { get; set; }
public string ImageSrc { get; set; }
public int ImageWidth { get; set; }
public int ImageHeight { get; set; }
public string ImageCode { get; set; }
}
The result with 12 images:
Result with 16 images:

Xamarin Forms: Grid button UI breaks when click restart button

I am using a button inside the grid for showing letters to implement a Word search game. Initially, the UI is looking good, but when clicks the play again button the UI breaks.
Screenshot:
Code for the setting button inside grid:
void SetGridLayout(char[,] matrixToPrint)
{
int numRows = matrixToPrint.GetLength(0);
int numCols = matrixToPrint.GetLength(1);
gridLayout.HorizontalOptions = LayoutOptions.FillAndExpand;
gridLayout.SetBinding(Button.HeightRequestProperty, new Binding("Width", source: gridLayout));
for (int row = 0; row < numRows; row++)
{
gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
}
for (int col = 0; col < numCols; col++)
{
gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
}
for (int rowIndex = 0; rowIndex < numRows; rowIndex++)
{
for (int columnIndex = 0; columnIndex < numCols; columnIndex++)
{
var Rowbutton = new Button
{
Text = Char.ToString(matrixToPrint[rowIndex, columnIndex]),
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Padding = 0,
Margin = 0,
BackgroundColor = Color.White
};
Rowbutton.SetBinding(Button.CommandProperty, "ClickCommand");
Rowbutton.SetValue(Button.CommandParameterProperty, new PassObject(Rowbutton, rowIndex.ToString() + "," + columnIndex.ToString()));
Rowbutton.SetBinding(Button.HeightRequestProperty, new Binding("Width", source: Rowbutton));
gridLayout.Children.Add(Rowbutton, columnIndex, rowIndex);
}
}
}
I tried a lot to find the cause behind this issue, but no luck. I have uploaded a sample project here for the reference. Thanks in advance.
you are adding new rows and cols to an existing Grid without clearing it first

Geometry intersection converting from direct geometry to buffergeometry

I am using Three.js. Found a really good Decal library written by Benpurdy. It's very easily modifiable and also used the techniques described here
However, the technique uses Geometry. The project I am on, uses BufferGeometry. I traced the code which does the geometry intersects and can't figure out the conversion from faces and vertices to attributes.
this.createGeometry = function(matrix, mesh) {
var geom = mesh.geometry;
var decalGeometry = new THREE.Geometry();
var projectorInverse = matrix.clone().getInverse(matrix);
var meshInverse = mesh.matrixWorld.clone().getInverse(mesh.matrixWorld);
var faces = [];
for(var i = 0; i < geom.faces.length; i++){
var verts = [geom.faces[i].a, geom.faces[i].b, geom.faces[i].c];
var pts = [];
var valid = false;
for(var v = 0; v < 3; v++) {
var vec = geom.vertices[verts[v]].clone();
vec.applyMatrix4(mesh.matrixWorld);
vec.applyMatrix4(matrix);
if((vec.z > 1) || (vec.z < -1) || (vec.x > 1) || (vec.x < -1) || (vec.y > 1) || (vec.y < -1)) {
} else {
valid = true;
}
pts.push(vec);
}
if(valid) {
var uv = [];
for(var n = 0; n < 3; n++){
uv.push(new THREE.Vector2( (pts[n].x + 1) / 2, (pts[n].y + 1) / 2));
pts[n].applyMatrix4(projectorInverse);
pts[n].applyMatrix4(meshInverse);
decalGeometry.vertices.push( pts[n] );
}
// update UV's
decalGeometry.faceVertexUvs[0].push(uv);
var newFace = geom.faces[i].clone();
newFace.a = decalGeometry.vertices.length - 3;
newFace.b = decalGeometry.vertices.length - 2;
newFace.c = decalGeometry.vertices.length - 1;
decalGeometry.faces.push(newFace);
}
}
return decalGeometry;
}
Appreciate if anyone could shed some light on how to go about pursuing this? Thanks.
I ended up solving the problem by writing another function to compute intersections with buffergeometry. Took me a while trying to understand the original buffer geometry code.
this.createGeometryFromBufferGeometry = function(matrix, mesh) {
var geom = mesh.geometry;
var decalGeometry = new THREE.Geometry();
var projectorInverse = matrix.clone().getInverse(matrix);
var meshInverse = mesh.matrixWorld.clone().getInverse(mesh.matrixWorld);
var faces = [];
for(var i = 0; i < geom.attributes.position.array.length; i+=9){
var pts = [];
var valid = false;
for(var v = 0; v < 9; v+=3) {
var vec = new THREE.Vector3(geom.attributes.position.array[i+v],geom.attributes.position.array[i+v+1],geom.attributes.position.array[i+v+2]);
console.log((i+v) + " " + (i+v+1) + " " + (i+v+2) );
console.log(vec);
vec.applyMatrix4(mesh.matrixWorld);
vec.applyMatrix4(matrix);
if((vec.z > 1) || (vec.z < -1) || (vec.x > 1) || (vec.x < -1) || (vec.y > 1) || (vec.y < -1)) {
} else {
valid = true;
}
pts.push(vec);
}
if(valid) {
var uv = [];
for(var n = 0; n < 3; n++){
uv.push(new THREE.Vector2( (pts[n].x + 1) / 2, (pts[n].y + 1) / 2));
pts[n].applyMatrix4(projectorInverse);
pts[n].applyMatrix4(meshInverse);
decalGeometry.vertices.push( pts[n] );
}
decalGeometry.faceVertexUvs[0].push(uv);
var newFace = new THREE.Face3()
newFace.a = decalGeometry.vertices.length - 3;
newFace.b = decalGeometry.vertices.length - 2;
newFace.c = decalGeometry.vertices.length - 1;
decalGeometry.faces.push(newFace);
}
}
return decalGeometry;
}
BufferGeometry() has a method .fromGeometry(). Populates this BufferGeometry with data from a Geometry object.
var geom = new THREE.BoxGeometry(1,1,1);
var bufGeom = new THREE.BufferGeometry().fromGeometry(geom);
UPD. You can use the other way round.
var bufGeom = new THREE.BoxBufferGeometry(1,1,1);
var geom = new THREE.Geometry().fromBufferGeometry(bufGeom);
Quick and dirty solution is to create geometry from bufferGeometry and after calculating dispose created geometry
this.compute = function()
{
this.geometry = mesh.geometry
if(this.geometry.attributes)
{
this.geometry = new THREE.Geometry().fromBufferGeometry(this.geometry);
this.computeDecal();
this.geometry.dispose();
}
else
{
this.computeDecal();
}
}

When I create pdf with itextg from ListView only the same listview child appears

I am trying to create a pdf from listview items. This is my listview:
This is the result:
Below is my code:
ListView def = (ListView) findViewById(R.id.ist);
ListAdapter adapter = def.getAdapter();
int itemscount = adapter.getCount();
/*int itemsposition = adapter.getItem(position);*/
Toast.makeText(getApplicationContext(), itemscount + " temaxia", Toast.LENGTH_LONG).show();
int allitemsheight = 0;
List<Bitmap> bmps = new ArrayList<Bitmap>();
for (int i = 0; i < itemscount ; i++) {
View childView = adapter.getView(i, null, def);
/*View childView = def.getChildAt(1);*/
childView.measure(View.MeasureSpec.makeMeasureSpec(def.getWidth(),
View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
childView.layout(0, 0, childView.getMeasuredWidth(),
childView.getMeasuredHeight());
childView.setDrawingCacheEnabled(true);
childView.buildDrawingCache();
childView.getDrawingCache();
/*bmps.add(childView.getDrawingCache());
allitemsheight+=childView.getMeasuredHeight();*/
Bitmap bigbitmap = Bitmap.createBitmap(def.getMeasuredWidth(),
childView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas bigcanvas = new Canvas(bigbitmap);
def.draw(bigcanvas);
Paint paint = new Paint();
bigcanvas.drawBitmap(bigbitmap,0,childView.getMeasuredHeight(),paint);
bigbitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
Image myImg = Image.getInstance(stream.toByteArray());
myImg.scalePercent(45, 60);
myImg.setAlignment(Image.ALIGN_CENTER);
// add image to document
doc.add(myImg);
doc.add( new Paragraph());
}
I just cant find why it only gets childview in first position despite it is inside a for loop. Can anyone help me? Thanks.
I changed all the consept to: Create a big image from all childviews and then cut it to multiple pages A4 size.See below....NOTICE that first doc is never opened and never closed,but after creating image document is opened and closed properly ...............
File file = new File(dir, flname + ".pdf");
FileOutputStream fOut = new FileOutputStream(file);
FileOutputStream fOut2 = new FileOutputStream(file);
pdfWriter.getInstance(doc, fOut);
// open the document
/* doc.open();*/
ByteArrayOutputStream stream = new ByteArrayOutputStream();
//////////////////////
ListView def = (ListView) findViewById(R.id.ist);
ListAdapter adapter = def.getAdapter();
int itemscount = adapter.getCount();
/*int itemsposition = adapter.getItem(position);*/
Toast.makeText(getApplicationContext(), itemscount + " temaxia", Toast.LENGTH_LONG).show();
View childView =null;
int allitemsheight = 0;
List<Bitmap> bmps = new ArrayList<Bitmap>();
for (int i = 0; i < itemscount ; i++) {
childView = adapter.getView(i,null,def);
/*childView = def.getChildAt(i);*/
childView.measure(View.MeasureSpec.makeMeasureSpec(def.getWidth(),
View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
childView.layout(0, 0, childView.getMeasuredWidth(),
childView.getMeasuredHeight());
childView.setDrawingCacheEnabled(true);
childView.buildDrawingCache();
/*childView.getDrawingCache();*/
bmps.add(childView.getDrawingCache());
allitemsheight+=childView.getMeasuredHeight();
}
Bitmap bigbitmap = Bitmap.createBitmap(def.getMeasuredWidth(),
allitemsheight , Bitmap.Config.ARGB_8888);
Paint paint = new Paint();
Canvas bigcanvas = new Canvas(bigbitmap);
for (int i = 0; i < bmps.size(); i++) {
Bitmap bmp = bmps.get(i);
bigcanvas.drawBitmap(bmp, 0, iHeight, paint);
/*bigcanvas.drawColor(Color.WHITE);
def.draw(bigcanvas);*/
iHeight+=bmp.getHeight();
bmp.recycle();
bmp=null;
}
bigbitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
Image myImg = Image.getInstance(stream.toByteArray());
myImg.scalePercent(45, 60);
myImg.setAlignment(Image.ALIGN_CENTER);
/*if(myImg.getWidth() >= doc.getPageSize().getWidth() || myImg.getHeight() >= doc.getPageSize().getHeight()){
myImg.scaleToFit(doc.getPageSize());
doc.newPage();
}
myImg.setAbsolutePosition((doc.getPageSize().getWidth() - myImg.getScaledWidth()) / BaseField.BORDER_WIDTH_MEDIUM, (doc.getPageSize().getHeight() - myImg.getScaledHeight()) / BaseField.BORDER_WIDTH_MEDIUM);
doc.add(myImg);
doc.add( new Paragraph());*/
///////////////////////////////////////
/////////////////////////////////////////
/////////////////////////////////////
Document document = new Document();
PdfWriter pdfWriter2 = PdfWriter.getInstance(document, fOut2);
document.open();
PdfContentByte content = pdfWriter2.getDirectContent();
myImg.scaleAbsolute(PageSize.A4);
myImg.setAbsolutePosition(0, 0);
float width = PageSize.A4.getWidth();
float heightRatio = myImg.getHeight() * width / myImg.getWidth();
int nPages = (int) (heightRatio / PageSize.A4.getHeight());
float difference = heightRatio % PageSize.A4.getHeight();
while (nPages >= 0) {
document.newPage();
content.addImage(myImg, width, 0, 0, heightRatio, 0, -((--nPages * PageSize.A4.getHeight()) + difference));
}
document.close();
} catch (DocumentException de) {
Log.e("PDFCreator", "DocumentException:" + de);
} catch (IOException e) {
Log.e("PDFCreator", "ioException:" + e);
} finally {
/*doc.close();*/
}

How to create grid border?

This is what I'm trying to create. White areas are System.Windows.Shapes.Rectangle in a Grid. This is my code for creating grid, columns, rows and rectangles;
Grid newGrid = new Grid();
for(int r=0; r<10; r++ ) {
newGrid.RowDefinitions.Add(
new RowDefinition { Height = new GridLength(30) });
for( int c=0; c<10; c++ ) {
newGrid.ColumnDefinitions.Add(
new ColumnDefinition { Width = new GridLength(30) });
Rectangle rec = new Rectangle{
Fill = new SolidColorBrush(Colors.White)
};
Grid.SetColumn(rec, c);
Grid.SetRow(rec, r);
newGrid.Children.Add(rec);
}
}
LayoutRoot.Children.Add(newGrid);
But I have not any idea how can add borders as we can see in picture. Thanks for suggestions.
Try
SolidColorBrush blackBrush = new SolidColorBrush();
blackBrush.Color = Colors.Black;
rec.Stroke = blackBrush;

Resources