i need to print a small report using PrintVisual function like following:
uc.DataContext = myDataTable.DefaultView; // us is UserControl
PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
pDialog.PrintQueue = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
pDialog.PrintTicket = pDialog.PrintQueue.DefaultPrintTicket;
pDialog.PrintTicket.PageScalingFactor = 1;
System.Printing.PrintCapabilities capabilities = null;
try
{
capabilities = pDialog.PrintQueue.GetPrintCapabilities();
}
catch
{
capabilities = null;
}
Viewbox vb = new Viewbox();
vb.Child = uc;
System.Windows.Size sz = new Size(520, 380);
vb.MinWidth = 1;
vb.MinHeight = 1;
vb.Measure(sz);
vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));
double scale = 1;
vb.LayoutTransform = new ScaleTransform(scale, scale);
pDialog.PrintVisual(vb, "MyViewBox");
the code works well in Win 8 and win 10 but not on win 7
any suggestions ?
Related
I am trying to make a Windows Form that shows display data from data a table. Every thing is working fine until I start scrolling in the Form using the auto scroll property.
I don't know why that's happening. I hope someone can help me.
private void allShowsToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
// Load All the Shows from the database
DataTable dt = accesse.LoadAllShows();
// Create the allShows From
Form allShows = new Form();
// Create the Controls for the AllShows form.
PictureBox[] pic = new PictureBox[dt.Rows.Count];
Label[] showName = new Label[dt.Rows.Count], season = new Label[dt.Rows.Count], eps = new Label[dt.Rows.Count], typ = new Label[dt.Rows.Count];
TextBox[] txtShowName = new TextBox[dt.Rows.Count], txtSeason = new TextBox[dt.Rows.Count], txtEps = new TextBox[dt.Rows.Count], txtTyp = new TextBox[dt.Rows.Count];
// AllShows Form properties
allShows.BackColor = Color.White;
allShows.Font = new Font("Calibri", 14f, FontStyle.Regular);
allShows.ForeColor = Color.Black;
allShows.Size = new Size(1050, 700);
allShows.StartPosition = FormStartPosition.CenterScreen;
allShows.AutoScroll = true;
allShows.AutoScrollMargin = new Size(0, 18);
// Variables
int y = 325; // the distens bettwen the controls on the Y and X.
bool xTurn = false; // the axies turn.
int yTurnNum = 0; // the y turn number.
for (int i = 0; i < dt.Rows.Count; i++)
{
// PictureBox Poster Properties
pic[i] = new PictureBox();
pic[i].BorderStyle = BorderStyle.FixedSingle;
pic[i].Size = new Size(162, 288);
pic[i].SizeMode = PictureBoxSizeMode.StretchImage;
pic[i].Image = Image.FromFile(dt.Rows[i][4].ToString());
// Label showName Properties
showName[i] = new Label();
showName[i].Text = "Show Name: " + dt.Rows[i][0];
showName[i].AutoSize = true;
// Label Season Properties
season[i] = new Label();
season[i].Text = "Season: " + dt.Rows[i][1];
season[i].AutoSize = true;
// Label Eps Properties
eps[i] = new Label();
eps[i].Text = "Episodes: " + dt.Rows[i][2];
eps[i].AutoSize = true;
// Label Typ Properties
typ[i] = new Label();
typ[i].Text = "Typ: " + dt.Rows[i][3];
typ[i].AutoSize = true;
if (xTurn)
{
// Sitting the location of the controls on the X turn
pic[i].Location = new Point(515, pic[i - 1].Location.Y);
showName[i].Location = new Point(687, showName[i - 1].Location.Y);
season[i].Location = new Point(687, season[i - 1].Location.Y);
eps[i].Location = new Point(687, eps[i - 1].Location.Y);
typ[i].Location = new Point(687, typ[i - 1].Location.Y);
xTurn = false;
}
else
{
// Sitting the location of the controls on the Y turn
pic[i].Location = new Point(15, 15 + (yTurnNum * y));
showName[i].Location = new Point(187, 20 + (yTurnNum * y));
season[i].Location = new Point(187, 55 + (yTurnNum * y));
eps[i].Location = new Point(187, 90 + (yTurnNum * y));
typ[i].Location = new Point(187, 125 + (yTurnNum * y));
yTurnNum += 1;
xTurn = true;
}
allShows.Controls.Add(pic[i]);
allShows.Controls.Add(showName[i]);
allShows.Controls.Add(season[i]);
allShows.Controls.Add(eps[i]);
allShows.Controls.Add(typ[i]);
}
allShows.ShowDialog();
}
catch (Exception ex)
{
tools.ShowErrorMessageBox(ex.Message, "Error");
}
}
I hope this gif will help you to understand what is happening.
enter image description here
I have C# project already done but im having issue with printing it's charts when comes out with more pages of data points, i got the scroll bar work when start getting more pages so the user can review all data on all pages but i could not find how to make the print preview shows them or print them,
when click on print, it shows only the first page on the print preview and same thing when print it out.
her is the print code:
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = this.chart1.Printing.PrintDocument;
((Form)ppd).WindowState = FormWindowState.Maximized;
chart1.Printing.PrintDocument.DefaultPageSettings.Landscape = true;
chart1.Printing.PrintDocument.DefaultPageSettings.Margins.Left = 0;
chart1.Printing.PrintDocument.DefaultPageSettings.Margins.Right = 0;
chart1.Printing.PrintDocument.DefaultPageSettings.Margins.Top = 0;
chart1.Printing.PrintDocument.DefaultPageSettings.Margins.Bottom = 0;
ppd.ShowDialog();
and here is the chart load code:
public void loadChart(string sqlvalue)//load chart method
{
chart1.ChartAreas[0].AxisY.Maximum = 55;
chart1.ChartAreas[0].AxisY.Minimum = 35;
chart1.ChartAreas[0].AxisY.Interval = 5;//control how many lines/Interval
chart1.ChartAreas[0].AxisY.ScrollBar.Enabled = true;
chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisX.Minimum = 0;
// chart1.ChartAreas[0].AxisX.Maximum = 10;
chart1.ChartAreas[0].AxisX.Interval = 1;
//X AXES label angle
chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 60;
da = new SqlDataAdapter(sqlvalue, cn.connect());
da.Fill(dt);
this.chart1.DataSource = dt;
this.chart1.Series["left"].XValueMember = dt.Columns[3].ToString();//date data
this.chart1.Series["left"].YValueMembers = dt.Columns[1].ToString();//spindle 1 data
this.chart1.Series["Right"].YValueMembers = dt.Columns[2].ToString();//spindle 2 data
//label the series lines, Backcolor and forcolor
chart1.Series[0].LabelBackColor = Color.Red;
chart1.Series[0].LabelForeColor = Color.White;
//datapoint marker's color, bordercolor,style and size
chart1.Series[0].MarkerColor = Color.White;
chart1.Series[0].MarkerBorderColor = Color.Black;
chart1.Series[0].MarkerStyle = MarkerStyle.Circle;
chart1.Series[0].MarkerSize = 8;
//datapoint marker's color, style and size
chart1.Series[1].MarkerColor = Color.White;
chart1.Series[1].MarkerBorderColor = Color.Black;
chart1.Series[1].MarkerStyle = MarkerStyle.Circle;
chart1.Series[1].MarkerSize = 8;
chart1.Series[1].LabelBackColor = Color.Blue;
chart1.Series[1].LabelForeColor = Color.White;
//Chart background lines color
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Silver;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Silver;
this.chart1.DataBind();
cn.disconnect();
// enable autoscroll
chart1.ChartAreas[0].CursorX.AutoScroll = true;//------------
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(0, 15);
chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
// set scrollbar small change to the target size
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = 15;
Legend left = new Legend();
Legend LC = CustomCloneLegend(chart1, left);
chart1.Legends.Add(LC);
chart1.Padding = Padding.Empty;
ChartArea CA = chart1.ChartAreas[0];
CA.Position = new ElementPosition(4,6, 100, 90);
}
Thank you for your time and help, here is the chart code update:
private static Image MergeImages(List<Image> imageList)
{
var finalSize = new Size();
foreach (var image in imageList)
{
if (image.Width > finalSize.Width)
{
finalSize.Width = image.Width;
}
finalSize.Height += image.Height;
}
var outputImage = new Bitmap(finalSize.Width, finalSize.Height);
using (var gfx = Graphics.FromImage(outputImage))
{
var y = 0;
foreach (var image in imageList)
{
gfx.DrawImage(image, 0, y);
y += image.Height;
}
}
return outputImage;
}
The second method:
List<Image> ChartsToImages(List<Chart> charts)
{
var imageList = new List<Image>();
foreach (var c in charts)
{
using (var ms = new MemoryStream())
{
c.SaveImage(ms, ChartImageFormat.Png);
var bmp = System.Drawing.Bitmap.FromStream(ms);
imageList.Add(bmp);
}
}
return imageList;
}
and this code
var chartList = new List<Chart> { chart1 };
var imageList = ChartsToImages(chartList);
var finalImage = MergeImages(imageList);
finalImage.Save("D:\\Junk.png", ImageFormat.Png);
Im not sure is that what you mean by your first comment, but i found this code here under Converting chart to image questions. this code convert and saves the chart in the same amount of pages but i need to show them in the printpreviewcontrol and print them.
Below code refers to the as per page count starting point and ending point based printing. And Grid view value chars are row loop based counting the page.
private int numberOfItemsPerPage = 0;
private int numberOfItemsPrintedSoFar = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int height = 480; //page height stating point
for (int l = numberOfItemsPrintedSoFar; l < dataGridView2.Rows.Count; l++)
{
numberOfItemsPerPage = numberOfItemsPerPage + 1;
if (numberOfItemsPerPage <= 25) // 25 is Page Line Item
{
numberOfItemsPrintedSoFar++;
if (numberOfItemsPrintedSoFar <= dataGridView2.Rows.Count)
{
height += dataGridView2.Rows[0].Height;
e.Graphics.DrawString(dataGridView2.Rows[l].Cells[0].FormattedValue.ToString(), dataGridView2.Font = new Font("Book Antiqua", 8), Brushes.Black, new RectangleF(5, height, dataGridView2.Columns[0].Width, dataGridView2.Rows[0].Height));
e.Graphics.DrawString(dataGridView2.Rows[l].Cells[1].FormattedValue.ToString(), dataGridView2.Font = new Font("Book Antiqua", 8), Brushes.Black, new RectangleF(170, height, dataGridView2.Columns[0].Width, dataGridView2.Rows[0].Height));
e.Graphics.DrawString(dataGridView2.Rows[l].Cells[2].FormattedValue.ToString(), dataGridView2.Font = new Font("Book Antiqua", 8), Brushes.Black, new RectangleF(290, height, dataGridView2.Columns[0].Width, dataGridView2.Rows[0].Height));
e.Graphics.DrawString(dataGridView2.Rows[l].Cells[3].FormattedValue.ToString(), dataGridView2.Font = new Font("Book Antiqua", 8), Brushes.Black, new RectangleF(345, height, dataGridView2.Columns[0].Width, dataGridView2.Rows[0].Height));
}
else
{
e.HasMorePages = false;
}
}
else
{
numberOfItemsPerPage = 0;
e.HasMorePages = true;
return;
}
}
numberOfItemsPerPage = 0;
numberOfItemsPrintedSoFar = 0;
}
I'm trying to implement a WPF Print function. It's working as long as the user doesnt want to print more than fits to one page. My Application enables the user to create xaml in runtime. Now i want to also enable him to print the xaml controls he created.
I have checked the total height of all xaml controls, devided by the pageheight and ceiled that number, so i know how many pages i have to print.
Next I'm creating a List of FrameworkElements for each page (see logic below) and store every List (each stands for one page) in an array.
At the end i want to create a preview which contains every page and enables the user to print all pages. In order to do that i have to put the pages together to a Document, but i dont know how. Please take a look at my code:
Package package = Package.Open("test.xps", FileMode.Create);
// Create new xps document based on the package opened
XpsDocument doc = new XpsDocument(package);
// Create an instance of XpsDocumentWriter for the document
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
// Write the canvas (as Visual) to the document
double height = element.ActualHeight;
double width = element.ActualWidth;
System.Windows.Controls.PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
Size pageSize = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight);
int pageCount = (int)Math.Ceiling(height / pageSize.Height);
if (pageSize.Height < height) {
var grid = element as Grid;
var children = grid.Children;
List<FrameworkElement>[] pages = new List<FrameworkElement>[pageCount-1];
int i = 0;
double currentHeight = 0;
foreach (FrameworkElement c in children) {
currentHeight += c.RenderSize.Height;
if (currentHeight < pageSize.Height) {
pages[i] = new List<FrameworkElement>();
pages[i].Add(c);
}
else {
i++;
currentHeight = 0;
pages[i] = new List<FrameworkElement>();
pages[i].Add(c);
}
}
for (int j = 0; j < pageCount; j++) {
var collator = writer.CreateVisualsCollator();
collator.BeginBatchWrite();
foreach (FrameworkElement c in pages[j]) {
collator.Write(c);
}
collator.EndBatchWrite();
}
}
doc.Close();
package.Close();
string filename = #"C:\Users\rzimmermann\Documents\Visual Studio 2012\Projects\MvvmLightPrintFunction\MvvmLightPrintFunction\bin\Debug\test.xps";
DocumentViewer viewer = new DocumentViewer();
doc = new XpsDocument(filename, FileAccess.Read);
viewer.Document = doc.GetFixedDocumentSequence();
Window ShowWindow = new Window();
ShowWindow.Width = 400;
ShowWindow.Height = 300;
ShowWindow.Content = viewer;
ShowWindow.Show();
#kenny is right you need to use the FixedPages. For a great tutorial pleas see: http://www.nbdtech.com/Blog/archive/2009/04/20/wpf-printing-part-2-the-fixed-document.aspx
As far as adding pages to a document you can do it like so:
doc.Pages.Add(page1Content);
doc.Pages.Add(page2Content);
//ect.
... PrintDialog dialog = new PrintDialog();
//dialog.PrintVisual(this.scrollCheckCardinfo, "");
Nullable<Boolean> print = dialog.ShowDialog();
if (print == true)
{
Grid DynamicGrid = new Grid();
DynamicGrid.Margin = new Thickness(100, 50, 0, 0);
RowDefinition gridRow1 = new RowDefinition();
gridRow1.Height = new GridLength(45);
RowDefinition gridRow2 = new RowDefinition();
DynamicGrid.RowDefinitions.Add(gridRow1);
DynamicGrid.RowDefinitions.Add(gridRow2);
TextBlock txtBlock1 = new TextBlock();
txtBlock1.Text = "Printed by xyz " + DateTime.Now.ToString();
txtBlock1.FontSize = 14;
txtBlock1.FontWeight = FontWeights.Bold;
txtBlock1.VerticalAlignment = VerticalAlignment.Top;
Grid.SetRow(txtBlock1, 0);
Grid.SetRow(this.scrollCheckCardinfo, 1);
DynamicGrid.Children.Add(txtBlock1);
DynamicGrid.Children.Add(CloneXaml(this.scrollCheckCardinfo));
dialog.PrintVisual(DynamicGrid, "xyz");
}...
public static T CloneXaml<T>(T source)
{
string xaml = XamlWriter.Save(source);
StringReader sr = new StringReader(xaml);
XmlReader xr = XmlReader.Create(sr);
return (T)XamlReader.Load(xr);
}
this.scrollCheckCardinfo is a Grid.
I need to Export my Chart as an image without showing it first in WPF. So i built the Chart in Code:
public void CreateHistogram(CalcRepository cr, int i)
{
Chart chart = new Chart();
chart.Width = 300;
chart.Height = 200;
chart.ScrollingEnabled = false;
chart.AnimationEnabled = false;
chart.TrendLines.Add(new TrendLine{Value = cr.Mean,Orientation = System.Windows.Controls.Orientation.Vertical});
chart.TrendLines.Add(new TrendLine{Value = cr.ChartTrippleNegativeStdDeviation,Orientation = System.Windows.Controls.Orientation.Vertical,LineStyle = LineStyles.Dashed});chart.TrendLines.Add(new TrendLine{Value = cr.ChartTripplePositiveStdDeviation,Orientation = System.Windows.Controls.Orientation.Vertical,LineStyle = LineStyles.Dashed});
chart.TrendLines.Add(new TrendLine{Value = cr.UpperSpecificationLimit,Orientation = System.Windows.Controls.Orientation.Vertical});
chart.TrendLines.Add(new TrendLine{Value = cr.LowerSpecificationLimit,Orientation = System.Windows.Controls.Orientation.Vertical});
chart.TrendLines[0].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[1].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[2].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[3].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[4].SetValue(Canvas.ZIndexProperty, 40);
chart.DataPointWidth = cr.DataPointWidth;
chart.Visibility = Visibility.Visible;
Axis x = new Axis();
x.AxisMaximum = cr.VisUpperBound;
x.AxisMinimum = cr.VisLowerBound;
x.AxisType = AxisTypes.Primary;
CustomAxisLabels cal = new CustomAxisLabels();
cal.Labels.Add(new CustomAxisLabel {From = cr.Mean, To = cr.Mean, Text = "Mean"});
cal.Labels.Add(new CustomAxisLabel {From = cr.ChartTrippleNegativeStdDeviation,To = cr.ChartTrippleNegativeStdDeviation,Text = "LCL"});
cal.Labels.Add(new CustomAxisLabel{From = cr.ChartTripplePositiveStdDeviation,To = cr.ChartTripplePositiveStdDeviation,Text= "UCL"});
cal.Labels.Add(new CustomAxisLabel {From = cr.UpperSpecificationLimit, To = cr.UpperSpecificationLimit , Text = "USL"});
cal.Labels.Add(new CustomAxisLabel {From = cr.LowerSpecificationLimit, To = cr.LowerSpecificationLimit, Text = "LSL"});
cal.FontSize = 10;
cal.Angle = 0;
cal.FontColor = new SolidColorBrush(Colors.Black);
cal.Enabled = true;
x.CustomAxisLabels.Add(cal);
chart.AxesX.Add(x);
var ds = new DataSeries();
var dpc = new DataPointCollection(cr.HistogramValues);
ds.DataPoints = dpc;
chart.Series.Add(ds);
ds.ZIndex = 1;
ds.Bevel = false;
ds.ShadowEnabled = false;
ds.LightingEnabled = false;
ds.Color = new SolidColorBrush(Colors.SteelBlue);
chart.BeginInit();
chart.EndInit();
chart.Measure(new Size(300, 200));
chart.Arrange(new Rect(0, 0, 300, 200));
chart.UpdateLayout();
ExportToPng(new Uri("C:\\" + i + ".png"), chart);
}
everything works fine, except the custom Axis Labels are missing. This is how the Output looks like:
As you can see, there is even space allocated for the CustomAxis Labels but they are not shown. Anyone got an idea?
Hint: AnimationEnabled has to be set false otherwise the series is not rendered yet when the image is taken - took me a long time to figure that out.
I found already a solution:
When exceeding the bounds, the values are set to Double.NaN. I found out, that the creation of all Labels fails, if any value in the Collections Double.Nan or Double.Infinity - Seems lika a bug in visifire.
I solved it by adding each Label in its seperate Collection.
I am using Windows Phone Toolkit - Nov 2011 (7.1 SDK) and I want to display multiple listpickers each
within a grid and each grid in a listbox. The problem is, only the first listpicker pops open and the rest don't. secondly how do I customize the full mode page of the listpicker to be displayed exclusively in Landscape orientation and set the page's "shell:SystemTray.IsVisible" to false.
Sorry I couldn't post a screenshot. error "Earn more than 10 reputation to post images".
Thanks
public MainPage()
{
InitializeComponent();
for (int g = 0; g < 10; g++)
{
// Define the margins template dor elements
Thickness elemThick = new Thickness();
// Create the Grid that will hold all the elements of a single entry
Grid entryGrd = new Grid();
entryGrd.VerticalAlignment = VerticalAlignment.Top;
entryGrd.HorizontalAlignment = HorizontalAlignment.Left;
elemThick.Left = 0;
elemThick.Bottom = 0;
elemThick.Right = 0;
elemThick.Top = 0;
entryGrd.Margin = elemThick;
entryGrd.Tag = lstbxPH.Items.Count;
// Setup the backgound value of the letBoder element
LinearGradientBrush elemLGB = new LinearGradientBrush();
elemLGB.EndPoint = new Point(0.5, 1);
elemLGB.StartPoint = new Point(0.5, 0);
GradientStop AquamarineGS = new GradientStop();
AquamarineGS.Color = Color.FromArgb(255, 127, 255, 212);
AquamarineGS.Offset = 0;
GradientStop greenLikeGS = new GradientStop();
greenLikeGS.Color = Color.FromArgb(255, 101, 250, 193);
greenLikeGS.Offset = 0.988;
elemLGB.GradientStops.Add(AquamarineGS);
elemLGB.GradientStops.Add(greenLikeGS);
// Draw the letter
for (int x = 0; x < 9; x++)
{
Border letBoder = new Border();
letBoder.Width = 53;
letBoder.Height = 51;
letBoder.VerticalAlignment = VerticalAlignment.Top;
letBoder.HorizontalAlignment = HorizontalAlignment.Left;
elemThick.Left = x * 60 + 71;
elemThick.Top = lstbxPH.Items.Count * 1 + 20;
letBoder.Margin = elemThick;
letBoder.Background = elemLGB;
// The Texblock
TextBlock let = new TextBlock();
let.VerticalAlignment = VerticalAlignment.Center;
let.HorizontalAlignment = HorizontalAlignment.Center;
let.FontSize = 25;
let.FontWeight = FontWeights.Bold;
let.Foreground = new SolidColorBrush(Color.FromArgb(200, 255, 255, 255));
let.Text = x.ToString();
let.Tag = x;
letBoder.Child = let;
entryGrd.Children.Add(letBoder);
}
// Draw the List picker element for the draw types
ListPicker DType = new ListPicker();
DType.Width = 48;
DType.VerticalAlignment = VerticalAlignment.Top;
DType.HorizontalAlignment = HorizontalAlignment.Left;
DType.Background = new SolidColorBrush(Color.FromArgb(200, 255, 255, 255));
DType.BorderBrush = new SolidColorBrush(Color.FromArgb(200, 255, 255, 255));
elemThick.Left = 17;
elemThick.Top = lstbxPH.Items.Count * 1 + 10;
DType.Margin = elemThick;
DType.FontSize = 18;
ListPickerItem item1 = new ListPickerItem() { Content = "A" };
ListPickerItem item2 = new ListPickerItem() { Content = "B" };
ListPickerItem item3 = new ListPickerItem() { Content = "C" };
DType.Items.Add(item1);
DType.Items.Add(item2);
DType.Items.Add(item3);
entryGrd.Children.Add(DType);
if (lstbxPH.Items.Count != 0)
{
// The delete button and related image
Button btnDel = new Button();
btnDel.Height = 65;
btnDel.Width = 60;
btnDel.Tag = lstbxPH.Items.Count;
btnDel.VerticalAlignment = VerticalAlignment.Top;
btnDel.HorizontalAlignment = HorizontalAlignment.Left;
btnDel.VerticalContentAlignment = VerticalAlignment.Top;
btnDel.HorizontalContentAlignment = HorizontalAlignment.Left;
elemThick.Left = 600;
elemThick.Top = lstbxPH.Items.Count + 13;
btnDel.Margin = elemThick;
elemThick.Left = 0;
elemThick.Bottom = 0;
elemThick.Right = 0;
elemThick.Top = 0;
btnDel.Name = "btnDel";
btnDel.Padding = elemThick;
btnDel.BorderBrush = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
Image imgDel = new Image();
imgDel.Source = new BitmapImage(new Uri("/appbar.delete.rest.png", UriKind.RelativeOrAbsolute));
imgDel.VerticalAlignment = VerticalAlignment.Top;
imgDel.HorizontalAlignment = HorizontalAlignment.Left;
imgDel.Height = 35;
imgDel.Width = 30;
elemThick.Left = 0;
elemThick.Bottom = 0;
elemThick.Right = 0;
elemThick.Top = 0;
imgDel.Margin = elemThick;
imgDel.Stretch = Stretch.UniformToFill;
btnDel.Content = imgDel;
entryGrd.Children.Add(btnDel);
}
// Add the grid with to the list box
this.lstbxPH.Items.Add(entryGrd);
}
}
This issue was actually solved by the Windows Phone Toolkit - Nov 2011 (7.1 SDK).
Here is how I worked it out.
Download the November release of the toolkit http://silverlight.codeplex.com/releases/view/75888
if you had a previous release of the toolkit installed, please uninstall it and unreferenced the tool kit on you project
Install the November release of the toolkit
Reference the toolkit on your project, debug and boom! it woks.