How to add buttons to a grid WP8.1 MVVM Light? - mvvm

I'm having trouble building a dashboard in WP8.1.
I'm using the MVVM Light toolkit.
I'm looking after this outcome:
screenshot of dashboard
I can currently build a dashboard but only with one object per row.
I've searched a lot but haven't found anything to get the desired effect.
Here's the code of the dashboard done programatically:
int i = 0;
Grid grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition());
for (int ct = 0; ct < 3; ct++)
grid.ColumnDefinitions.Add(new ColumnDefinition());
StackPanel stackPanel = new StackPanel();
stackPanel.Name = "stackPanel";
stackPanel.Background = new SolidColorBrush(new Windows.UI.Color());
foreach (var flow in dashboard.DashboardFlows)
{
if (flow.Flow.IsInstalled)
{
//if next object should change line
if (i == 3)
{
stackPanel.Children.Add(grid);
grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition());
for (int ct = 0; ct < 3; ct++)
grid.ColumnDefinitions.Add(new ColumnDefinition());
i = 0;
}
Button button = new Button();
if (flow.Flow.Type.Equals("COMPNEWS"))
{
button.Click += delegate { Frame.Navigate(typeof(NewsPage), flow); };
}
//button stackpanel
StackPanel stack = new StackPanel();
//Button image
Image buttonImage = new Image();
if (!String.IsNullOrEmpty(flow.Flow.IconUrl) || !String.IsNullOrWhiteSpace(flow.Flow.IconUrl))
buttonImage.Source = new BitmapImage(new Uri(flow.Flow.IconUrl));
buttonImage.Height = 45;
buttonImage.VerticalAlignment = VerticalAlignment.Top;
stack.Children.Add(buttonImage);
//Button name
TextBlock buttonName = new TextBlock();
buttonName.Text = flow.Flow.Name;
buttonName.FontSize = 12;
buttonName.TextWrapping = TextWrapping.Wrap;
stack.Children.Add(buttonName);
button.Content = stack;
button.Margin = new Thickness(5, 0, 5, 0);
button.SetValue(Grid.ColumnProperty, i);
button.SetValue(Grid.RowProperty, 0);
button.HorizontalAlignment = HorizontalAlignment.Stretch;
button.VerticalAlignment = VerticalAlignment.Stretch;
button.Background = new SolidColorBrush(Color.FromArgb(130, 30, 30, 30));
grid.Children.Add(button);
i++;
}
}
scroll.Content = stackPanel;
Thank you in advance.

Related

Unable to clear the table in RCP

I am new in RCP. I have created one table and using TableEditor for some columns for putting Label and Progress bar.
But For some cases I want to clear the table. For textual content table.removeAll(); is working but its not clear the Label and Progress bar;
public void createPartControl(Composite parent) {
toolkit = new FormToolkit(parent.getDisplay());
compositeObj = toolkit.createComposite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
compositeObj.setLayout(layout);
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 4;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
myTable = new Table(compositeObj,
SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.CHECK);
myTable .setLayoutData(gridData);
final int[] bounds = { 30, 80, 100, 80, 100, 50, 100, 50, 50, 70, 50, 50 };
for (int i = 0; i < titles.length; i++) {
TableColumn tblColumn = new TableColumn(btsTable, SWT.NONE);
tblColumn.setText(titles[i]);
tblColumn.setWidth(bounds[i]);
tblColumn.setResizable(true);
tblColumn.setMoveable(true);
tblColumn.pack();
}
myTable.setHeaderVisible(true);
myTable.setLinesVisible(true);
for (int i = 0; i < receiverViewDataProvider.size(); i++) {
items[i] = new TableItem(btsTable, SWT.NONE);
}
fillData();
}
Table Filling Method
{
items[cntIndex].setText(1, sID);
items[cntIndex].setText(2, sName);
editor[cntIndex] = new TableEditor(myTable);
signalStrengthLabel1[selCnt] = toolkit.createLabel(myTable, sText, SWT.CENTER);
editor[cntIndex].grabHorizontal = true;
if (bIsAllow == true)
editor[cntIndex].setEditor(nameLabel1[selCnt], items[cntIndex], 3);
editor[cntIndex] = new TableEditor(myTable);
pbReverse[selCnt] = new ProgressBar(myTable, SWT.HORIZONTAL);
pbReverse[selCnt].setMinimum(0);
pbReverse[selCnt].setMaximum(30);
signalStrengthLabel1[selCnt].setText("" + iLevel + "");
pbReverse[selCnt].setSelection(iLevel);
editor[cntIndex].grabHorizontal = editor[cntIndex].grabVertical = true;
if (bAllow == true)
editor[cntIndex].setEditor(pbReverse[selCnt], items[cntIndex], 4);
}
Tried
for (int Index = 0; Index < Cnt; Index++) {
nameLabel1[btsIndex].setText("");
pbReverse[selIndex].setMaximum(0);
pbReverse[Index].setVisible(false);
editor[Index].dispose();
}
myTable.removeAll();
I am getting below result but want to clear the whole table

Hundred thousands of datatable records to PDF in web API

I'm trying to create PDF from the DataTable in web api using ADO.Net. Unfortunately based on filters some times I may get very less records & able to download without any problem. Sometimes may be very huge like 200 thousand of records. When I'm checking in local my system its getting hang while converting the dt to PDF. My code is like below:
private FileContentResult ExportPDF(DataTable dataTable)
{
string Name = "Logs";
System.IO.MemoryStream mStream = new System.IO.MemoryStream();
byte[] content = null;
try
{
string[] columnNames = (from dc in dataTable.Columns.Cast<DataColumn>() select dc.ColumnName).ToArray();
int count = columnNames.Length;
object[] array = new object[count];
dataTable.Rows.Add(array);
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, mStream);
int cols = dataTable.Columns.Count;
int rows = dataTable.Rows.Count;
HeaderFooter header = new HeaderFooter(new Phrase(Name), false);
// Remove the border that is set by default
header.Border = iTextSharp.text.Rectangle.TITLE;
// Align the text: 0 is left, 1 center and 2 right.
header.Alignment = Element.ALIGN_CENTER;
pdfDoc.Header = header;
// Header.
pdfDoc.Open();
iTextSharp.text.Table pdfTable = new iTextSharp.text.Table(cols, rows);
pdfTable.BorderWidth = 1; pdfTable.Width = 100;
pdfTable.Padding = 1; pdfTable.Spacing = 4;
//creating table headers
for (int i = 0; i < cols; i++)
{
Cell cellCols = new Cell();
Chunk chunkCols = new Chunk();
iTextSharp.text.Font ColFont = FontFactory.GetFont(FontFactory.HELVETICA, 14, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.Black);
chunkCols = new Chunk(dataTable.Columns[i].ColumnName, ColFont);
cellCols.Add(chunkCols);
pdfTable.AddCell(cellCols);
}
//creating table data (actual result)
for (int k = 0; k < rows; k++)
{
for (int j = 0; j < cols; j++)
{
Cell cellRows = new Cell();
iTextSharp.text.Font RowFont = FontFactory.GetFont(FontFactory.HELVETICA, 12);
Chunk chunkRows = new Chunk(dataTable.Rows[k][j].ToString(), RowFont);
cellRows.Add(chunkRows);
pdfTable.AddCell(cellRows);
}
}
pdfDoc.Add(pdfTable);
pdfDoc.Close();
content = mStream.ToArray();
return File(content, "application/pdf", "LogReports.pdf");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

xamarin.ios ios-chart BarChartDataSet

Just port ios-charts v2.2.3.0 from Xamarin Nuget package manager.
public void BarChart(BarChartModel _barChartModel, BarChartView _barChartView, string _fromView, bool animateChart)
{
try {
barChartModel = _barChartModel;
barChartView = _barChartView;
barChartView.SetDrawBarShadowEnabled (false);
barChartView.SetMaxVisibleValueCount (15);
barChartView.SetPinchZoomEnabled (true);
barChartView.SetDrawGridBackgroundEnabled (false);
barChartView.ScaleYEnabled = false;
// Chart axis' layout configurations
ChartXAxis xAxis = barChartView.XAxis;
xAxis.SetLabelPosition (XAxisLabelPosition.Bottom);
xAxis.SetDrawGridLinesEnabled (false);
xAxis.SetLabelTextColor (chartTextColor);
xAxis.SpaceBetweenLabels = 2;
xAxis.SetAvoidFirstLastClippingEnabled (true);
xAxis.SetLabelWidth (30f);
ChartYAxis leftAxis = barChartView.LeftAxis;
leftAxis.SetLabelCount (10, false);
leftAxis.SetLabelPosition (YAxisLabelPosition.OutsideChart);
leftAxis.SpaceTop = 10f;
leftAxis.SetLabelTextColor (chartTextColor);
leftAxis.ValueFormatter = new NSNumberFormatter ();
ChartYAxis rightAxis = barChartView.RightAxis;
rightAxis.SetDrawGridLinesEnabled (false);
rightAxis.SetDrawLabelsEnabled (false);
ChartLegend legend = barChartView.Legend;
legend.SetPosition (ChartLegendPosition.BelowChartCenter);
legend.SetForm (ChartLegendForm.Square);
legend.FormSize = 9f;
legend.SetFormToTextSpace (11f);
legend.XEntrySpace = 15f;
legend.TextColor = chartTextColor;
// X Axis
// -- directly get from dataModel.xAxis;
NSObject[] truncatedXAxis = new NSObject[barChartModel.xAxis.Count];
for (int t = 0; t < barChartModel.xAxis.Count; t++) {
if (barChartModel.xAxis [t].Length > 13)
truncatedXAxis [t] = NSObject.FromObject (barChartModel.xAxis [t].Substring (0, 11) + "..");
else
truncatedXAxis [t] = NSObject.FromObject (barChartModel.xAxis [t]);
}
// Y Axis
BarChartDataSet[] yDataSets = new BarChartDataSet[barChartModel.yAxis.Count];
for (int i = 0; i < barChartModel.yAxis.Count; i++) {
ChartDataEntry[] barEntry = new ChartDataEntry[barChartModel.yAxis [i].Count];
//List<ChartDataEntry> dataEntryList = new List<ChartDataEntry>();
for (int j = 0; j < barChartModel.yAxis [i].Count; j++) {
barEntry[j] = new ChartDataEntry((float)barChartModel.yAxis [i] [j], j);
//dataEntryList.Add(new ChartDataEntry((float)barChartModel.yAxis [i] [j], j));
}
//BarChartDataSet yDataSet = new BarChartDataSet (dataEntryList.ToArray(), barChartModel.dataSetLegend [i].ToString());
// Crashes HERE V
BarChartDataSet yDataSet = new BarChartDataSet (barEntry, barChartModel.dataSetLegend [i].ToString());
yDataSet.SetColor(chartColors [i]);
yDataSets[i] = yDataSet;
}
// Combine xAxis & yAxis
BarChartData data = new BarChartData (truncatedXAxis, yDataSets);
data.SetValueTextColor (chartTextColor);
data.SetHighlightEnabled (false); // Disable highlight selection
barChartView.SetData(data);
barChartView.SetNoDataTextDescription ("");
barChartView.SetDescriptionText (""); // Disable description - barChartData.SetDescription (String.IsNullOrEmpty (dataModel.name) ? "" : dataModel.name);
barChartView.SetNoDataText (""); // Text displayed when no data is given ("You need to provide data for the chart.");
if (animateChart)
barChartView.AnimateWithYAxisDuration (800);
} catch (Exception ex) {
LogHelper.Debug ("iOSChartHelper", ex.Message, ex);
}
}
The line below this comment // Crashes HERE V is where having crash with below error message throw from binding framework.
fatal error: NSArray element failed to match the Swift Array Element type
Have tried changes the BarchartDataSet to different variable but no luck.
Does anyone have sample code or solution about this issue?
Your barEntry array is a ChartDataEntry array. You should use an Array of BarChartDataEntry
BarChartDataEntry[] barEntry = new BarChartDataEntry[someIntValue];

OxyPlot Zero Line

We have a simple ColumnChart with positive and negative values.
There is no line across the chart though at the 0 line. How do we enable a zero line across?
See attached image
Assuming that you are using a LinearAxis for Y axis.
All you need to do is add to your LinearAxis.
plotModel.Axes.Add(new LinearAxis()
{
Title = "Percentage",
Position = AxisPosition.Left,
// Magic Happens here we add the extra grid line on our Y Axis at zero
ExtraGridlines = new Double[] { 0 }
});
Take a look at this works for me on Android haven't tested it on IOS:
public static PlotModel Withnegativevalues()
{
var plotModel1 = new PlotModel();
plotModel1.LegendBorderThickness = 0;
plotModel1.LegendOrientation = LegendOrientation.Horizontal;
plotModel1.LegendPlacement = LegendPlacement.Outside;
plotModel1.LegendPosition = LegendPosition.BottomCenter;
plotModel1.Title = "With negative values";
var categoryAxis1 = new CategoryAxis();
categoryAxis1.MinorStep = 1;
categoryAxis1.Labels.Add("Category A");
categoryAxis1.Labels.Add("Category B");
categoryAxis1.Labels.Add("Category C");
categoryAxis1.Labels.Add("Category D");
categoryAxis1.ActualLabels.Add("Category A");
categoryAxis1.ActualLabels.Add("Category B");
categoryAxis1.ActualLabels.Add("Category C");
categoryAxis1.ActualLabels.Add("Category D");
plotModel1.Axes.Add(categoryAxis1);
var linearAxis1 = new LinearAxis();
linearAxis1.MaximumPadding = 0.06;
linearAxis1.MinimumPadding = 0.06;
linearAxis1.ExtraGridlines = new Double[1];
linearAxis1.ExtraGridlines[0] = 0;
plotModel1.Axes.Add(linearAxis1);
var columnSeries1 = new ColumnSeries();
columnSeries1.StrokeThickness = 1;
columnSeries1.Title = "Series 1";
columnSeries1.Items.Add(new ColumnItem(25,-1,"OxyColors.Automatic"));
columnSeries1.Items.Add(new ColumnItem(137,-1,"OxyColors.Automatic"));
columnSeries1.Items.Add(new ColumnItem(18,-1,"OxyColors.Automatic"));
columnSeries1.Items.Add(new ColumnItem(40,-1,"OxyColors.Automatic"));
plotModel1.Series.Add(columnSeries1);
var columnSeries2 = new ColumnSeries();
columnSeries2.StrokeThickness = 1;
columnSeries2.Title = "Series 2";
columnSeries2.Items.Add(new ColumnItem(-12,-1,"OxyColors.Automatic"));
columnSeries2.Items.Add(new ColumnItem(-14,-1,"OxyColors.Automatic"));
columnSeries2.Items.Add(new ColumnItem(-120,-1,"OxyColors.Automatic"));
columnSeries2.Items.Add(new ColumnItem(-26,-1,"OxyColors.Automatic"));
plotModel1.Series.Add(columnSeries2);
var columnSeries3 = new ColumnSeries();
columnSeries3.StrokeThickness = 1;
columnSeries3.Title = "Series 3";
columnSeries3.Items.Add(new ColumnItem(21,-1,"OxyColors.Automatic"));
columnSeries3.Items.Add(new ColumnItem(8,-1,"OxyColors.Automatic"));
columnSeries3.Items.Add(new ColumnItem(48,-1,"OxyColors.Automatic"));
columnSeries3.Items.Add(new ColumnItem(3,-1,"OxyColors.Automatic"));
plotModel1.Series.Add(columnSeries3);
var columnSeries4 = new ColumnSeries();
columnSeries4.StrokeThickness = 1;
columnSeries4.Title = "Series 4";
columnSeries4.Items.Add(new ColumnItem(-8,-1,"OxyColors.Automatic"));
columnSeries4.Items.Add(new ColumnItem(-21,-1,"OxyColors.Automatic"));
columnSeries4.Items.Add(new ColumnItem(-3,-1,"OxyColors.Automatic"));
columnSeries4.Items.Add(new ColumnItem(-48,-1,"OxyColors.Automatic"));
plotModel1.Series.Add(columnSeries4);
return plotModel1;
}

About collapse panel which panel selected

I have a question about collapse panel..
I have a placeholder and I add more than one headerpanel, contentpanel, collapsiblepanel dynamically.. Here is my code :
CollapsiblePanelExtender cpe = new CollapsiblePanelExtender();
Panel pnlheader,pnlcontent;
Label lblcontent,lblheader; Button btn;
for (int i = 0; i < 10; i++)
{
///// PANEL HEADER VE ICERIGI //////////
pnlheader = new Panel();
pnlheader.ID = "PanelHeader" + i;
pnlheader.BackColor = System.Drawing.Color.Blue;
lblheader = new Label();
lblheader.ID = "LabelHeader" + i.ToString();
lblheader.Text = (i + 1) + ". Header";
pnlheader.Controls.Add(lblheader);
/////////PANEL CONTENT VE ICERIGI //////////
pnlcontent = new Panel();
pnlcontent.ID = "PanelContent" + i;
pnlcontent.BackColor = System.Drawing.Color.DarkRed;
lblcontent = new Label();
lblcontent.ID = "LabelContent" + i.ToString();
lblcontent.Text = "<table><tr><td border=\"1\">DENEMEE</td></tr></table>";
btn = new Button();
btn.ID = "Button" + i.ToString();
btn.Text = "Deneme.Button";
pnlcontent.Controls.Add(lblcontent);
pnlcontent.Controls.Add(btn);
///////// COLLAPSEPANEL ICERIGI///////
cpe = new CollapsiblePanelExtender();
cpe.ID = "CollapsePanel" + i;
cpe.TargetControlID = "PanelContent" + i;
cpe.ExpandControlID = "PanelHeader" + i;
cpe.CollapseControlID = "PanelHeader" + i;
PlaceHolder2.Controls.Add(pnlheader);
PlaceHolder2.Controls.Add(pnlcontent);
PlaceHolder2.Controls.Add(cpe);
}
How can I understand which panel expanded..
it is very important, please help..
Firstly you should to find all controls of CollapsiblePanelExtender type inside the scope of PlaceHolder2.
Then you'll be able to get Collapsed property of each found CollapsiblePanelExtender instance.