Windows Phone 8.1 AppBarButton icon with 2 rows of text - winrt-xaml

I would like to know how to make AppBarButton Icon to has 2 rows of text. I want to make it like in Windows Calendar:

The AppBarButton doesn't display text or arbitrary Xaml in its Icon. It needs to be a symbol from a font, bitmap, or path. For a calendar display like that you'll be best off with a bitmap.
Since you probably don't want to pregenerate 366 icons you can use RenderTargetBitmap to create them on the fly. Assuming "ButtonImageMaster" is a Xaml snippet with the day and month and calendarButton is the AppBarButton:
RenderTargetBitmap rtb = new RenderTargetBitmap();
await rtb.RenderAsync(ButtonImageMaster);
IBuffer pixelBuffer = await rtb.GetPixelsAsync();
string fileName = "calIcon.png";
StorageFile calIconFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(fileName,CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream stream = await calIconFile.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Straight,
(uint)rtb.PixelWidth,
(uint)rtb.PixelHeight,
DisplayInformation.GetForCurrentView().LogicalDpi,
DisplayInformation.GetForCurrentView().LogicalDpi,
pixelBuffer.ToArray());
await encoder.FlushAsync();
}
BitmapIcon icon = new BitmapIcon();
icon.UriSource = new Uri("ms-appdata:///temp/"+fileName);
calendarButton.Icon = icon;

On WP 8.1 Silverlight, you can useWriteableBitmap(FrameworkElement element, Transform transform) constructor of WriteableBitmap (which is derived from ImageSource) to generate a 'screenshot of memory-rendered framework element'. Then you can set it to Bitmap Icon.

Related

Print activity of android studio

I want to print my layout activity directly with a button, I don't know is neccesary pass activity to PDF format o directly to print.
Thanksenter image description here
In order to get the root view of your activity as image, do this:
View view = getWindow().getDecorView().findViewById(android.R.id.content);
view.setDrawingCacheEnabled(true);
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),View. MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
And to print:
PrintHelper photoPrinter = new PrintHelper(this); // Asume that 'this' is your activity
photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
photoPrinter.printBitmap("print", bitmap);

How to make a part of string bold in a in a UI label

I want to make bold some part of a big string. I am using Xamarin iOS and getting a big string from API. I need to make some part of the string as bold I tried <b>some text </b> this will not work for mono touch. What is the best option to make a string bold in run time in xamrin. iOS or in winforms applications?
Use AttributedString to apply attributes to different parts of the string. See example below that will only make the first half of the string bold
var BoldString = new NSMutableAttributedString (original_string);
var BoldTextAttributes = new UIStringAttributes {
Font = UIFont.FromName ("Helvetica-Bold", 20f)
};
BoldString.SetAttributes (BoldTextAttributes.Dictionary, new NSRange (0, OutOfStock.Length / 2)); // this range will apply the attribute only to the first half of the string
MyLabel.AttributedText = BoldString; // Assign the attributed text to your label

Add text label to WPF Bing Maps

Is it possible to add text to specified location (lat/long) in WPF bing maps?
Yes, c# code-behind I'll assume?
// I just created a Location object from the mouseclick but you can replace labelLocation with anything
Microsoft.Maps.MapControl.WPF.Location labelLocation = myMap.ViewportPointToLocation(mousePosition);
// Create a label
Label customLabel = new Label();
customLabel.Content = "Text here";
// With map layers we can add WPF children to lat long (WPF Location obj) on the map.
MapLayer labelLayer = new MapLayer();
labelLayer.AddChild(customLabel, labelLocation );
myMap.Children.Add(labelLayer);

Aspose.Words...calculating widt of text in pixels

I have an MVC3 C# .Net web app. I am using Aspose.Words to create an MS Word document. I have a requirement to not include tables in the document. However, on several lines of the document the alignment of the text is mis-aligned depending on the width of the text.
For example:
This looks good
Proposal Name: My Proposal Date:04/24/2012
This does not
Proposal Name: My Prop Date:04/24/2012
It should be
Proposal Name: My Prop Date:04/24/2012
Based on the width of the first bit of text, I need to calculate the width in pixels (I think) and insert a TAB if necessary.
Any ideas how to do this?
you can use Graphics.MeasureString function which gives you the width of your string in pixels based on your font. for more info go Here
Cheers,
Ehsan
The following code example returns the bounding rectangle of the current entity relative to the page top left corner.
Document doc = new Document(MyDir + "in.docx");
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
var renderObject = layoutCollector.GetEntity(para);
layoutEnumerator.Current = renderObject;
RectangleF location = layoutEnumerator.Rectangle;
Console.WriteLine(location);
}
src: https://www.aspose.com/community/forums/thread/541215/replace-run-text-with-string-of-spaces-of-same-pixel-length.aspx

setIcon in j2me to set icons for buttons

I am trying to put in an icon (a scaled image) as part of a button that also contains some text. I am programming in J2ME for the Nokia SDK (S60 device) and using Eclipse.
The code is as follows:
but = new Button("Some text");
Image img = null;
try {
img = Image.createImage("/flower.png");
} catch(IOException e) {
e1.printStackTrace();
}
but.setIcon(img);
The above lines are the code that works properly. I am facing problems in scaling the image to the size of the button. Whenever I try to do that, I get a divide by zero error. The function I am using to scale the image and the way it is being scaled is:
Image img2 = null;
img2 = img.scaled(but.getWidth()/2, but.getHeight());
but.setIcon(img2);
I am unable to figure out why I get a divide by zero error every time I try to run the above code. Is there some other function that I should use? Or is there something I am missing ?
which UI Framework are using, is it LWUIT? if yes, you can't get the width/height of any component before showing the form, you should use getPreferredWidth instead

Resources