Windows phone Textblock not showing large text - windows-phone-7

How to show large text string in windows phone using textblock or richtextbox ?
currently I am facing issue to show large amount of text in textbox its truncated

On Windows Phone there is a constraint on the size of any single control such that it avoids the creation of very large surfaces needing to be drawn and that would definitely impact performance.
There are various approaches to solving this and there's an example of a work around that automatically takes text and breaks it up over multiple TextBlocks at http://blogs.msdn.com/b/priozersk/archive/2010/09/08/creating-scrollable-textblock-for-wp7.aspx
If you have a more specific example and repro please update your question with this.

To resolve this issue we created a converter. So to start we should place a ContentPresenter on the page instead of TextBlock in order to display content we like
<ContentPresenter Content="{Binding BodyText,Converter={StaticResource LongTextConverter}}" />
public string BodyText
{
get
{
return "Lorem ipsum dolor sit amet, ...";
}
}
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
UIElement result = null;
if (value != null)
{
string data = value.ToString();
if (data.Length <= MinLength)
{
result = new TextBlock
{
Text = data,
Style = App.Current.Resources["ArticleBodyStyle"] as Style,
HorizontalAlignment = HorizontalAlignment.Stretch
};
}
else
{
StackPanel resultPanel = new StackPanel();
int min = 0;
int max = MinLength;
while (true)
{
string temp = data.Substring(min, max - min);
if (max != data.Length)
{
int index = temp.LastIndexOf('\n');
index = index == -1 ? temp.LastIndexOf('.') + 1 : -1;
max = (index == -1) ? max : index;
temp = data.Substring(min, max) + '\n';
resultPanel.Children.Add(new TextBlock
{
Margin = new Thickness(12, 0, 12, -30),
Text = temp,
Style = App.Current.Resources["ArticleBodyStyle"] as Style,
HorizontalAlignment = HorizontalAlignment.Stretch
});
}
else
{
resultPanel.Children.Add(new TextBlock
{
Margin = new Thickness(12, 0, 12, 0),
Text = temp,
Style = App.Current.Resources["ArticleBodyStyle"] as Style,
HorizontalAlignment = HorizontalAlignment.Stretch
});
break;
}
min += max;
max = min + MinLength;
if (max > data.Length)
{
max = data.Length;
}
}
result = resultPanel;
}
}
return result;
}

Related

How do the obstacle detection sensors work in the DJI Windows SDK?

I want to get the distance of the obstacles in the back and front of the Mavic Air.
I'm using the VissionDetectionStateChanged and it returns values in the 4 sectors, but all of them change only with obstacles in the back. If I put my hand in the front, nothing happens.
The VisionSensorPosition is returning TAIL always and when I put my hand very close to the tail of the aircraft it changes for NOSE.
Shouldn't be the opposite?
Right now I just display the information, but I'd like to be able to detect obstacles in the back and front of the aircraft to try to keep it in the middle of two objects and avoid collisions.
This is my code in the event:
private async void FlightAssistant_VissionDetectionStateChanged(object sender, VissionDetectionState? value)
{
if (value.HasValue)
{
if (txtPosition.Dispatcher.HasThreadAccess)
{
txtPosition.Text = value.Value.position.ToString();
for (int i = 0, count = value.Value.detectionSectors.Count; i < count; i++)
{
ObstacleDetectionSector sector = value.Value.detectionSectors[i];
TextBox txtWarning = this.FindControl<TextBox>("txtWarning" + i.ToString());
if (txtWarning != null)
txtWarning.Text = sector.warningLevel.ToString();
TextBox txtObstacleDistance = this.FindControl<TextBox>("txtObstacleDistance" + i.ToString());
if (txtObstacleDistance != null)
txtObstacleDistance.Text = sector.obstacleDistanceInMeters.ToString();
}
}
else
{
await txtPosition.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
txtIsSensorBeingUsed.Text = value.Value.isSensorBeingUsed.ToString();
txtPosition.Text = value.Value.position.ToString();
for (int i = 0, count = value.Value.detectionSectors.Count; i < count; i++)
{
ObstacleDetectionSector sector = value.Value.detectionSectors[i];
TextBox txtWarning = this.FindControl<TextBox>("txtWarning" + i.ToString());
if (txtWarning != null)
txtWarning.Text = sector.warningLevel.ToString();
TextBox txtObstacleDistance = this.FindControl<TextBox>("txtObstacleDistance" + i.ToString());
if (txtObstacleDistance != null)
txtObstacleDistance.Text = sector.obstacleDistanceInMeters.ToString();
}
});
}
}
}

How do I determine column number using itext 7

I have created documents using itext 7 and its ColumnDocumentRenderer. I would like to force some text into the last column. By "last column" I mean for example if I have a single page defined by ColumnDocumentRenderer to have 3 columns but I only have one column of text, I still want column 3 to contain my forced value. So I suppose (presupposing a solution, others appreciated) that I would need mechanisms to know the column number I'm in and to force a column break. Since StackOverflow wants this in the form of a question, (a) what are these mechanisms? and (b) what are alternative approaches?
Question How to skip text insertion point to the next column using iText? apparently asks a similar question but apparently is using an earlier release of itext; mine has no ColumnText that I can find.
Thanks in advance for any help.
I was answering from my phone yesterday, but now that I have access to a computer, I changed ColumnDocumentRenderer like this:
public class ColumnDocumentRenderer extends DocumentRenderer {
protected Rectangle[] columns;
protected int nextAreaNumber;
public ColumnDocumentRenderer(Document document, Rectangle[] columns) {
super(document);
this.columns = columns;
}
public ColumnDocumentRenderer(Document document, boolean immediateFlush, Rectangle[] columns) {
super(document, immediateFlush);
this.columns = columns;
}
#Override
protected LayoutArea updateCurrentArea(LayoutResult overflowResult) {
if (overflowResult != null && overflowResult.getAreaBreak() != null && overflowResult.getAreaBreak().getType() != AreaBreakType.NEXT_AREA) {
nextAreaNumber = 0;
}
if (nextAreaNumber % columns.length == 0) {
super.updateCurrentArea(overflowResult);
}
return (currentArea = new LayoutArea(currentPageNumber, columns[nextAreaNumber++ % columns.length].clone()));
}
public int getNextAreaNumber() {
return nextAreaNumber;
}
}
The change will be in iText 7.0.1, but you can use this code in your own renderer.
You can now use this renderer like this:
public void createPdf(String dest) throws IOException {
OutputStream fos = new FileOutputStream(dest);
PdfWriter writer = new PdfWriter(fos);
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
float offSet = 36;
float gutter = 23;
float columnWidth = (PageSize.A4.getWidth() - offSet * 2) / 3 - gutter * 2;
float columnHeight = PageSize.A4.getHeight() - offSet * 2;
Rectangle[] columns = {
new Rectangle(offSet, offSet, columnWidth, columnHeight),
new Rectangle(offSet + columnWidth + gutter, offSet, columnWidth, columnHeight),
new Rectangle(offSet + 2 * (columnWidth + gutter), offSet, columnWidth, columnHeight)};
ColumnDocumentRenderer renderer = new ColumnDocumentRenderer(document, columns);
document.setRenderer(renderer);
for (int i = 0; i < 50; i++) {
document.add(new Paragraph("Hello World"));
}
while (renderer.getNextAreaNumber() % 3 != 0)
document.add(new AreaBreak());
document.add(new Paragraph("Third column"));
document.add(new AreaBreak());
for (int i = 0; i < 80; i++) {
document.add(new Paragraph("Hello World"));
}
while (renderer.getNextAreaNumber() % 3 != 0)
document.add(new AreaBreak());
document.add(new Paragraph("Third column"));
document.add(new AreaBreak());
for (int i = 0; i < 10; i++) {
document.add(new Paragraph("Hello World"));
}
while (renderer.getNextAreaNumber() % 3 != 0)
document.add(new AreaBreak());
document.add(new Paragraph("Third column"));
document.close();
}
The first column has index 0 and the next area number is 1, the second column has index 1 and the next area number is 2, and so on.
This means that you can check for and go to the third column on a page like this.
while (renderer.getNextAreaNumber() % 3 != 0)
document.add(new AreaBreak());

What is the function of Message sender in xamarin.forms

What is the function of Message sender in xamarin.forms? In my app I have cart contain list view and a Grant Total label. Is it possible to update the label using message sender? I can get the total amount from my sqlite db I need to update it to the view.
This is my number picker index change event in view cell
numPicker.SelectedIndexChanged += (sender, args) =>
{
// var price = _cartQuery.GetSum();
sender = BindingContext;
// cm_items item = (cm_items)sender;
if(Int32.Parse(btn_NumBtn.Text)<=1)
{
lbl_Price.Text = ((numPicker.SelectedIndex + 1) * (Int32.Parse(lbl_Price.Text))).ToString();
btn_NumBtn.Text = (numPicker.SelectedIndex + 1).ToString();
}
else
{
int a = Int32.Parse(lbl_Price.Text);
int b = Int32.Parse(btn_NumBtn.Text);
int c = a / b;
lbl_Price.Text = ((numPicker.SelectedIndex + 1) * c).ToString();
btn_NumBtn.Text = (numPicker.SelectedIndex + 1).ToString();
}
_cartQuery.UpdatePicker((BindingContext as CartDB).Cart_Item_Id, numPicker.SelectedIndex + 1, Int32.Parse(lbl_Price.Text));
price = _cartQuery.GetSum();
// App.Instance.ViewModel.TotalAmount = price;
// _cartDB.total = App.Instance.ViewModel.TotalAmount;
Calculate_price();
numPicker.IsEnabled = false;
};
Calculate_price method
public double Calculate_price()
{
try
{
var price = 0;
price = _cartQuery.GetSum();
App.Instance.ViewModel.TotalAmount = price;
return price;
}
catch (Exception ex)
{
throw ex;
}
}
In my view i have a label named grant total, i need to update the total on e number picker change
Label lbl_amnt = new Label
{
// Text = viewModel.Price.ToString(),
// Text=CartCell.price.ToString(),
Text = price.ToString(),
FontSize = 18,
FontAttributes = FontAttributes.Bold,
TextColor = Color.FromRgb(102, 204, 102),
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand,
};
lbl_amnt.SetBinding(Label.TextProperty, "TotalAmount");
update to my post as per the comment from #Grish
In my view model i have this TotalAmount as a property
public double _TotalAmount;
public double TotalAmount
{
get { return _TotalAmount; }
set { _TotalAmount = value; OnPropertyChanged("TotalAmount");}
}
I think the better solution is i notify but the thing is view is not binding
Binding is definitely the answer in your case. I think the problem is that you bind string (label's text) to property of type double.
You should specify IValueConverter or stringFormat parameters in your call to SetBinding.
Check this link:
https://forums.xamarin.com/discussion/19146/binding-to-integers

Wrap AutoCompleteField List Item

My apps has AutoCompleteField that hold long text more than 100 Characters, if I use regular AutoCompleteField I cant read the rest of data.
How can I make the text wrap into 2 or more lines in the autocompletefield options ?
I try using '\r'+'\n' and '\n', its not giving new line. setting it size and also set row height doesnt give me the result I wanted
AutoCompleteField autoCustomer = new AutoCompleteField(custList, style);
autoCustomer.getListField().setSize(20);
autoCustomer.getListField().setRowHeight(100);
If I was you I would override drawListRow and draw the text using drawText which will give me total control on how the row should look. Try adapting your code to behave like this
AutoCompleteField autoCompleteField = new AutoCompleteField(
filterList, AutoCompleteField.LIST_STATIC) {
public void drawListRow(ListField listField, Graphics g,
int index, int y, int width) {
BasicFilteredListResult result = (BasicFilteredListResult) (autoCompleteField
.get(listField, index));
if (result != null)
{
//Draw text here
}
}
public void onSelect(Object selection, int type) {
super.onSelect(selection, type);
if (selection != null) {
BasicFilteredListResult result = (BasicFilteredListResult) this
.getSelectedObject();
handleResult((String) result._object);
} else {
Dialog.alert(Resource
.getString(PLEASE_PICK_A_VALID_NAME));
return;
}
}
};
IF you want to wrap your text you can use the following method
// Handy method to wrap text drawn with the specified font into rows with
// the max width
// Found here:
// http://supportforums.blackberry.com/t5/Java-Development/Can-drawText-wrap-text-into-multiple-lines/m-p/499901
public static String[] wrapText(String text, Font f, int maxWidth) {
Vector result = new Vector();
if (text == null)
return new String[] {};
boolean hasMore = true;
// The current index of the cursor
int current = 0;
// The next line break index
int lineBreak = -1;
// The space after line break
int nextSpace = -1;
while (hasMore) {
// Find the line break
while (true) {
lineBreak = nextSpace;
if (lineBreak == text.length() - 1) {
// We have reached the last line
hasMore = false;
break;
}
nextSpace = text.indexOf(' ', lineBreak + 1);
if (nextSpace == -1)
nextSpace = text.length() - 1;
int linewidth = f
.getAdvance(text, current, nextSpace - current);
// If too long, break out of the find loop
if (linewidth > maxWidth)
break;
}
String line = text.substring(current, lineBreak + 1);
result.addElement(line);
current = lineBreak + 1;
}
String[] resultArray = new String[result.size()];
result.copyInto(resultArray);
return resultArray;
}

Datagridview - drawing rectangle on datagridview problem c# windows forms

I have 3 questions:
wheter I am doing my task in a good way
why when I scroll dataGridView, painted rectangles dissapear..
why painting is so slow...
Here is the code in which I want to draw a colorful rectangle with text on groups of cells in each column, that have the same values, empty values shouldn't have rectangles
void DataGridView1CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
foreach (DataGridViewColumn column in this.dataGridView1.Columns){
string tempCellValue = string.Empty;
int tempRectX = -1;
int tempRectY = -1;
int tempRectYEnd = -1;
int tempRectWidth = -1;
int tempRectHeight = -1;
foreach (DataGridViewRow row in this.dataGridView1.Rows){
Rectangle rect = this.dataGridView1.GetCellDisplayRectangle(
column.Index, row.Index,true);
DataGridViewCell cell = dataGridView1.Rows[row.Index].Cells[column.Index];
if ( cell.Value!=null){
if (tempRectX==-1){
tempRectX = rect.Location.X;
tempRectY = rect.Location.Y;
tempCellValue = cell.Value.ToString();
}else
if (cell.Value.ToString()!=tempCellValue){
tempRectYEnd = rect.Location.Y;
Rectangle newRect = new Rectangle(tempRectX,
tempRectY , 5 ,
tempRectYEnd );
using (
Brush gridBrush = new SolidBrush(Color.Coral),
backColorBrush = new SolidBrush(Color.Coral))
{
using (Pen gridLinePen = new Pen(gridBrush))
{
e.Graphics.FillRectangle(backColorBrush,newRect);
} }
tempRectX=-1;
tempCellValue = string.Empty;
}
}else if (tempRectX!=-1){
tempRectYEnd = rect.Location.Y;
Rectangle newRect = new Rectangle(tempRectX,
tempRectY , 50 ,
tempRectYEnd );
using (
Brush gridBrush = new SolidBrush(Color.Coral),
backColorBrush = new SolidBrush(Color.Coral))
{
using (Pen gridLinePen = new Pen(gridBrush))
{
e.Graphics.FillRectangle(backColorBrush,newRect);
} }
tempRectX=-1;
tempCellValue = string.Empty;
}
}}
The DataGridView1CellPainting event is intended to Paint or change Paint behaviour for one cell.
DGV raises this event for each visible Cell.
When Paint other cells, your code slow down.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellpaintingeventargs.aspx

Resources