Exception when using SkiaSharp API in Xamarin Forms Tabbed Page - exception

I'm facing some problems at the time of painting a circle with the SkiaSharp API in one of the children pages of a Tabbed Page in Xamarin Forms.
Although I get no errors during the building of the project, whenever I enter the page in which the circle is supposed to be drawn during the on device debugging, the application throws a "System.InvalidCastException: Specified cast is not valid" message and it crashes.
This is the XAML code of the Tabbed Page:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:me="clr-namespace:TestBth;assembly=TestBth"
x:Class="TestBth.MyTabbedPage">
<TabbedPage.Children>
<me:ConnectPage />
<me:LissajousPage />
<me:ParametersPage />
</TabbedPage.Children>
<!--Pages can be added as references or inline-->
</TabbedPage>
This is the XAML code of the page that's causing the trouble:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:skia="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms"
xmlns:local="clr-namespace:TestBth"
x:Class="TestBth.LissajousPage"
Title="Lissajous">
<skia:SKCanvasView x:Name="canvasView"
PaintSurface="canvasView_PaintSurface" />
</ContentPage>
And this is the internal code of the same page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using SkiaSharp;
using SkiaSharp.Views.Forms;
namespace TestBth
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LissajousPage : ContentPage
{
SKPaint blackFillPaint = new SKPaint
{
Style = SKPaintStyle.Fill,
Color = SKColors.Black
};
public LissajousPage()
{
InitializeComponent();
}
private void canvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
SKSurface surface = e.Surface;
SKCanvas canvas = surface.Canvas;
canvas.Clear(SKColors.CornflowerBlue);
int width = e.Info.Width;
int height = e.Info.Height;
//Set transforms
canvas.Translate(width / 2, height / 2);
canvas.Scale(width / 200f);
//Clock Background
canvas.DrawCircle(0, 0, 100, blackFillPaint);
}
}
}
Any idea about why could this be happening?
Thanks in advance.

For my surprise, it turns out the SkiaSharp.Views.Forms Nuget package was not installed for Android.
I specified that I wanted to install it in all my projects but there must have been a problem during the installation.
I installed the package individually for Android and it works fine now.
Sorry for the inconvenience.

Related

Primefaces p:galleria won't display images separately

My galleria won't work like it does in the showcase. It displays the images all at once with the style of a bulleted list
picture 1
picture 2
I pretty much copied the code from the showcase website (link). But it doesn't work at all like it should. I used Mozilla Firefox and Internet Explorer for testing. Both same result.
I'm running on a glassfish 5.0. Using Java 8, PrimeFaces 6.0 and JSF 2.1.
Both images have a resolution of 711 x 400.
Here is my code.
xhtml
<p:galleria var="currentImage" value="#{homeBean.images}" panelWidth="500" panelHeight="313"
showCaption="true">
<p:graphicImage value="/image/#{currentImage}"></p:graphicImage>
</p:galleria>
Java-Bean
#ManagedBean
#ApplicationScoped
public class HomeBean {
private final List<String> images;
{
images = new ArrayList<>();
images.add("image1.png");
images.add("image2.png");
}
public List<String> getImages() {
return images;
}
}
But this is how its displayed

Put wizard navbar on top position

I'm working with a wizard component. The navbar is in the botton but my boss wants me to put it in the top of the wizard,I thought that it was an attribute or tag to do it straight forward but I have been reviewing the documentation and I should be wrong (I only found the showNavBar tag).
Is there a way to do it without css or jquery? (we have some problems in the application setting css when working with some components so I would like to avoid it).
Thank you very much
You can achieve this in either of the two ways:
1 - Extending the WizardRenderer
By extending the WizradRenderer you can change the order of the encoding.
In the original Renderer the encodeContent(facesContext, wizard); is called before encodeNavigators(facesContext, wizard); so it's pretty much simple, extend you custom renderer, change the order of the calls.
public class ExNavWizardRenderer extends org.primefaces.component.wizard.WizardRenderer{
#Override
protected void encodeMarkup(FacesContext facesContext, Wizard wizard) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
String clientId = wizard.getClientId(facesContext);
String styleClass = wizard.getStyleClass() == null ? "ui-wizard ui-widget" : "ui-wizard ui-widget " + wizard.getStyleClass();
writer.startElement("div", wizard);
writer.writeAttribute("id", clientId, "id");
writer.writeAttribute("class", styleClass, "styleClass");
if(wizard.getStyle() != null) {
writer.writeAttribute("style", wizard.getStyle(), "style");
}
if(wizard.isShowStepStatus()) {
encodeStepStatus(facesContext, wizard);
}
// encode the navigators before the content
if(wizard.isShowNavBar()) {
encodeNavigators(facesContext, wizard);
}
encodeContent(facesContext, wizard);
writer.endElement("div");
}
}
Update your faces-config.xml
<render-kit>
<renderer>
<component-family>org.primefaces.component</component-family>
<renderer-type>org.primefaces.component.WizardRenderer</renderer-type>
<renderer-class>com.projectPackage.ExNavWizardRenderer</renderer-class>
</renderer>
</render-kit>
2 - jQuery
In your document.ready you can change the DOM, for example this would do the same as the Renderer:
$('.ui-wizard-step-titles').after($('.ui-wizard-navbar'))

How to set codes in html page?

I am new in html and i'm making a html page in which i want to display some code, but it not showing proper way like what we are writing in notepad. So, i have to write each and every line or any other solution is there. Suppose this is the code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.liste);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// Setup the list view
final ListView prestListView = (ListView) findViewById(R.id.list);
final prestationAdapterEco prestationAdapterEco = new prestationAdapterEco(this, R.layout.prestation);
prestListView.setAdapter(prestationAdapterEco);
// Populate the list, through the adapter
for(final prestationEco entry : getPrestations()) {
prestationAdapterEco.add(entry);
}
prestListView.setClickable(true);
prestListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Object o = prestListView.getItemAtPosition(position);
String str=(String)o;//As you are using Default String Adapter
Toast.makeText(getApplicationContext(),str,Toast.LENGTH_SHORT).show();
}
});
}
and i want to show it on html page like this only. Please help.. Thanks
<pre><code> code... </code></pre>
This seems to be the best method they've found here: <code> vs <pre> vs <samp> for inline and block code snippets
It also happens to be the recommended way to show a sample of computer code on W3.org.
I think you're looking for code/syntax highlighting in HTML pages. Unfortunately there is no highlighting feature using tags in HTML.
In HTML You can use:
<code>You code goes here..</code>
For more reference: http://www.w3schools.com/tags/tag_code.asp and the list of global attributes code tag supports: http://www.w3schools.com/tags/ref_standardattributes.asp
However, you can make use of some javascripts which enables syntaxt highlighting in HTML.
You can check this thread: "Syntax highlighting code with Javascript" for more info.

Show only month and year in DatePicker WP8

<toolkit:DatePicker Value="2/28/2010" />
I need show only month and year in my date picker (WP8). I've tried to do this in such way, but it was not working:
<toolkit:DatePicker Value="{Binding DateValue}" ValueStringFormat="{}{0:MM-yyyy}" />
I need it for DatePickerPage too.
You cannot implement this by adding xaml string format. For implement such functionality you need to edit the toolkit code. For that you can download the open source code from CodePlex. After downloading the project find the Date Picker class and edit the relevant methods to remove the date. recompile the source in release mode and you can use that new dll.
If you don't want to copy the page from Codeplex, you can extend the page and override the GetSelectorsOrderedByCulturePattern method to change the day selector's visibility. In the example below I've fixed it to month then year, which you may not want in your version. Also I'm accessing controls by name, so take care with future updates to WindowsPhone Toolkit.
<toolkit:DatePickerPage
x:Class="MyApp.MonthYearPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
</toolkit:DatePickerPage>
And
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Controls.Primitives;
using System.Diagnostics;
using System.Windows.Media;
namespace MyApp
{
public partial class MonthYearPage : DatePickerPage
{
public MonthYearPage()
{
InitializeComponent();
}
protected override IEnumerable<LoopingSelector> GetSelectorsOrderedByCulturePattern()
{
var PrimarySelector = ((Grid)Content).FindName("PrimarySelector") as LoopingSelector;
var SecondarySelector = ((Grid)Content).FindName("SecondarySelector") as LoopingSelector;
var TertiarySelector = ((Grid)Content).FindName("TretiarySelector") as LoopingSelector;
var selectors = GetSelectorsOrderedByCulturePattern(
"DMY",
new char[] { 'Y', 'M', 'D' },
new LoopingSelector[] { PrimarySelector, SecondarySelector, TertiarySelector });
// Passing "DMY" in on the previous line makes sure the day selector
// is the first one in the enumeration. You may want to change the order
// of 'M' and 'Y' in that string for your needs or depending on region.
selectors.First<LoopingSelector>().Visibility = Visibility.Collapsed;
return selectors;
}
}
}
{}{0:"Y","y"} have a good day :D ( information here --> http://msdn.microsoft.com/en-us/library/az4se3k1%28v=VS.95%29.aspx)
This should help to format the DateTimeButton content to display month and year only:
<toolkit:DatePicker x:Name="datePicker" ValueStringFormat="{}{0:y}"/>
Format exhibited depending on the location but this can be avoided by writing this:
<toolkit:DatePicker
Value="{Binding DateCard, Mode=TwoWay}"
ValueStringFormat="{}{0:MM'/'yy}" />
And you will be happy!(dd'/'MM'/'yyy)

Empty first line in razor mvc 4 rc

I've migrated from mvc 3 to mvc 4 and encountered with the following problem.
#using InvoiceDocflow.Controllers
#{
Response.ContentType = "text/xml";
}
<?xml version="1.1" encoding="UTF-8" ?>
<dc>
#foreach (var dcLink in (IEnumerable<DcLink>)ViewData["SupportedDcs"])
{
<link rel="#dcLink.RelUri.ToString()" href="#dcLink.DcUri.ToString()" />
}
</dc>
This is my view. My layout is just one line
#RenderBody()
So in mvc 3 <?xml version="1.1" encoding="UTF-8" ?> appeared in the first line, but now, its appears on the second line, leaving th first line empty.
Can I make it render on the first line as it was in mvc 3?
By the way.
#using InvoiceDocflow.Controllers
#{
Response.ContentType = "text/xml";
}<?xml version="1.1" encoding="UTF-8" ?>
This would work, but this is not what I whant to do at all.
I ran into a similar problem with blank lines at the top of the page when trying to return a cache manifest file. Solution, Add a Response.Write("..."), this will be at the first line of the page.
#{
Layout = null;
Response.Write("CACHE MANIFEST");
} .......
Temporary fix? ActionFilter and strip out the empty first line? Clearly you could also do other minification on the response if suitable.
public class TranslationFilter : MemoryStream
{
private Stream filter = null;
public TranslationFilter(HttpResponseBase httpResponseBase)
{
filter = httpResponseBase.Filter;
}
public override void Write(byte[] buffer, int offset, int count)
{
var response = UTF8Encoding.UTF8.GetString(buffer);
// remove all newlines
response = response.Replace(System.Environment.NewLine, "");
/* remove just first empty line
if (response.Substring(0, 2) == "\r\n")
{
response = response.Substring(2, response.Length - 2);
} */
filter.Write(UTF8Encoding.UTF8.GetBytes(response), offset, UTF8Encoding.UTF8.GetByteCount(response));
}
}
public class ResponseFilter : ActionFilterAttribute
{
public ResponseFilter()
{
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
base.OnResultExecuted(filterContext);
filterContext.HttpContext.Response.Filter = new TranslationFilter(filterContext.HttpContext.Response);
}
}
And add it onto the Controller method?
[ResponseFilter]
public ActionResult Index()
{
return View();
}
I know this is an old question but I found it when I was searching for a solution to this problem.
Since no one has an easy solution, here is mine:
I was able to fix this by using a partial view instead of a normal view.
I believe the problem comes down to the layout, even if you set it to null it still seems to add a blank first line. The #{} ads a blank line also, so you must move it to the bottom of your view.
So just add a partial view and have your controller return the partial view as such:
public ActionResult GenerateXML()
{
return PartialView("_XML");
}
Then in your partial view you will need to set it up like this (with your #{} at the bottom):
#model string
<?xml version="1.0" encoding="UTF-8" ?>
<response>
<message>#Model</message>
</response>
#{ Response.ContentType = "text/xml";}
This will result in an HTML source of:
<?xml version="1.0" encoding="UTF-8" ?>
<response>
<message>Response Message</message>
</response>
I hope this helps others who run into this problem.
I know you suggested just moving the tag to the end of the #{} but why not place it before that. Moreover, is this blank space causing an error or an issue? You can clearly see that it is because of whitespace created by your code and not from mvc or razor.
Perhaps something like this:
#using InvoiceDocflow.Controllers
<?xml version="1.1" encoding="UTF-8" ?>
#{
Response.ContentType = "text/xml";
}
None of the solutions above worked for me, so after spending a long time trying to fix it - it should be very easy since it's just an empty line - I wrote a blog post about it.
http://devstuffs.wordpress.com/2014/02/07/first-line-empty-in-razor/
I solved the similar problem this way:
_ViewStart.cshtml
#{
Layout = null;
Response.Write("<!DOCTYPE html>");
}
Another .cshtml
#model ViewModel<EshopWebsiteOrder>
<html>
<head>
<meta charset="utf-8" />
Finally, it makes sense define common DOCTYPE on one place.
Another simple fix without the ResponseFilter. Simply put the #using at the bottom of the cshtml file:
<?xml version="1.1" encoding="UTF-8" ?>
<dc>
#foreach (var dcLink in (IEnumerable<DcLink>)ViewData["SupportedDcs"])
{
<link rel="#dcLink.RelUri.ToString()" href="#dcLink.DcUri.ToString()" />
}
</dc>
#using InvoiceDocflow.Controllers
#{
Response.ContentType = "text/xml";
}
If you move:
<?xml version="1.1" encoding="UTF-8" ?>
into the top of a Layout template then have your xml page inherit that and output your xml data it should work.