Hi, I want to implement the ISectionindexer for the Adapter for Android in Listviews. Any easy way to do it?
ListView Indexing?
Exception when navigating back to Frame in ListView
I have one page with xaml definition:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App3.Pages.Page1">
<ScrollView>
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame>
<Label Text="{Binding Nazwa}"/>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
</ContentPage>
When I navigate to another page using
Navigation.PushAsync(new Page2());
and then press physical BACK button on Windows Phone 8.1 Emulator i get Exception (with minimal stacktrace - from Forms code)
{System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] ---> System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] ---> System.Windows.Markup.XamlParseException: [Line: 0 Position: 0]
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
--- End of inner exception stack trace ---
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options)
at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom)
at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom)
at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated)
at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport)
at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize)
at Xamarin.Forms.Platform.WinPhone.FixedLongListSelector.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
--- End of inner exception stack trace ---}
If I remove Frame element, no exception is thrown.
how to create/redirect page on specific platform?
For example, in my XF PCL project I have page A working on Android, IOS and WP but I have page B, It works only on Android and IOS, for windows phone I want to create Page B under the WindowsPhone project rather than PCL. I am navigating from page A to page B in PCL project. how do I handle this that I redirect to Page B under WP project when I am on WP? Because I will still have same named page on PCL (only android and IOS)
BLOB to Image Binding
I have to bind images from a SQLite database. The images are stores as BLOB (png file).
var image = new Image
{
HorizontalOptions = LayoutOptions.Start,
WidthRequest = 40,
HeightRequest = 40
};
var bnd = new Binding("Image", BindingMode.Default, new ArrayToImageConverter());
image.SetBinding(Image.SourceProperty, bnd);
How to define an "ArrayToImageConverter"
public abstract class ArrayToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
byte[] bmp = value as byte[];
if (bmp == null)
return null;
return new StreamImageSource
{
Stream = ?????
};
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new System.NotImplementedException();
}
}
Button - Tapped Event
I've created a carousel form. It has four buttons on a form. Currently, it is a demo but will be populated with data later. Buttons on form one correspond to 1-4 and buttons on form two are 5-8 which match my datamodel.
How do I add the tapped event to my button also ensuring that the button is connecting to the correct record?
var objButton = new Button
{
Image = image,
Style = StylesCOnstants.ButtonStyle
};
//Button Clicked Event
objButton.Clicked += async (sender, e) =>
{
vmController.Tapped = Pass in Tapped for button 1 or 5
}
How can I bind data from a source to a picker dynamically.
I have a situation where I need to bind data to a picker from a data source. Can anyone help me in writing the XAML and XAML.cs code.
Crash when creating MainActivity
I'm getting a nasty exception in my Xamarin.Forms app:
System.NotSupportedExceptionUnable to activate instance of type MyApp.Droid.MainActivity from native handle.
>
System.MissingMethodExceptionNo constructor found for MyApp.Droid.MainActivity::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
I've tried to add the missing constructor and call base from it, but the compiler won't let me. It claims the base class doesn't have such a constructor. This is patently untrue, however: MainActivity <- MyApplicationActivity <- FormsApplicationActivity <- Activity which does have that constructor:
protected Activity (IntPtr javaReference, JniHandleOwnership transfer);
The compiler won't cooperate, and my app crashes because the JNI abstraction leaks. See the discussion here for more details.
So I'm between a rock and a hard place.
What to do?
Is there an alternative to AVPlayer that can be used in Xamarin.Forms with iOS and Android?
I want to take a product that is iOS only currently using AVPlayer and convert it to a Xamarin.Forms app, but I need an alternative. I've haven't been able to find one currently and I was hoping someone had a suggestion.
Common Footer for all content pages
Hi,
I have implemented Base class for all content page in Xamarin Form and used ToolbarItems for add top menus.
Same I want something which can add menus at the bottom of all pages(like footer).
Thanks,
Pramod
Windows Phone 8.1, "Package.appxmanifest is not well-formed XML"
I've got a Xamarin.Forms solution that I've been developing for iOS and Android, using the Prism MVVM framework and everything has been going great.
I decided to install Visual Studio 2013 Express and add in a Windows Phone 8.1 project because I want to also target that platform. No matter what I do, I keep getting this error when adding the new project (Store Apps > Windows Phone Apps > Blank App (Windows Phone) ), and after adding all the necessary NuGet packages. Totally stumped. Here's the build error message:
Content of the file 'Package.appxmanifest' is not well-formed XML. Root element is missing. [path].WinPhone\Package.appxmanifest
The Package.appxmanifest XML looks fine. I'll attach it here.
I'd appreciate any ideas.
Notification over a toolbar item.
I have a toolbar in my Xamarin forms project. I require the following -
1. I need to display notifications on my toolbar items as in the image - .
2. I need to decrease space between the toolbar items and move them to right side.
3. I need to change the color of extreme right 3 dot icon from grey to white. Its coming by default when I am adding some items with ToolbarItemOrder as Secondary.
Image link - https://www.dropbox.com/s/54k4w594to4rbbl/toolbar.PNG?dl=0
Can anyone please suggest how can I fulfill this requirements. Sample code will be appreciable.
Here is my code -
this.ToolbarItems.Clear();
this.ToolbarItems.Add(new ToolbarItem("Home", "menu_dot", async () => { }, ToolbarItemOrder.Secondary));
this.ToolbarItems.Add(new ToolbarItem("My Account", "menu_dot", async () => { }, ToolbarItemOrder.Secondary));
this.ToolbarItems.Add(new ToolbarItem("My Profile", "menu_dot", async () => { }, ToolbarItemOrder.Secondary));
this.ToolbarItems.Add(new ToolbarItem("", "right_icon1.png", async () => {}, ToolbarItemOrder.Primary));
this.ToolbarItems.Add(new ToolbarItem("", "right_icon2.png", async () => { }, ToolbarItemOrder.Primary));
this.ToolbarItems.Add(new ToolbarItem("", "right_icon3.png", async () => { }, ToolbarItemOrder.Primary));
Thanks
Xamarin With Sencha Touch UIs
Have anyone tried developing Xamarin Forms App(for iOS or Android Platform) with Forms Page used as a container and Sencha Touch Based UIs are displayed using WebView(Forms or Native) control. If so, please share the issues/challenges in integrating,
1. Exchange of Data between Xamarin & Sencha UIs, Vice-versa
Assumption : Data is available in Forms and binding it on to Sencha UI Controls.
2. Any limitation on Data Size being passed or wildcard\newline\tab characters
Handing of Parsing the passed data inside Sencha.
3. Invoking Xamarin(c#) functions from Sencha
Does Sencha support calling C# functions.
Thanx In Advance.
how to Solve Xamarin.Auth Package error?
Hi
i have used xamarin starter edition.(trial)
I am developing a Xamarin.form app in that i have google+,facebook login integration using xamarin.auth.when i add a package xamarin.Auth i facing these errors:
Could not install package 'Xamarin.Auth.NoXamStore 1.0.0'. You are trying to install this package into a project that targets 'portable-net45+win+wp80+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
What can i do now?
Application logo removed but still display in android 5.1.1 version
Hi,
I have removed application logo displayed before the page header (action bar).
I have checked in Genymotion (emulator) it get removed, but when i checked in mobile(Android 5.1.1 version) it still displayed.
For this i used below code in MainActivity.cs
ActionBar.SetIcon(null);
Radio Button in PCL Project
Hi
I am trying to use radio buttons in my PCL project, unfortunately I did not get any success, even I used XLabs, but failed to keep radio button horizontal, please suggest me how to use radio button with image in PCL, XAML or c# code
Strange white overlay in WebView with ContentEditable and AppCompat
Hi,
I have a quite peculiar problem.
In my app I have a WebView
used as a form by inserting a div with contentEditable
set to true. It all worked fine until the update to AppCompat
styles.
Now, a strange white overlay (white square) appears when the user tries to write inside the WebView
, that disappears when the keyboard is dismissed. In order to find the root cause of the problem I have created a sample project with just one page containing just a vertical stack layout containing another stack layout and the webview. What I have noticed is that this problem happens if the height of the internal stack layout is enough for the webview to be covered by the keyboard when it appears. In this case the webview is pushed up, and this strange overlay appears. The webview is fully functional, and it is possible to write text, even though it is hidden by this white square, that disappears when the keyboard is dismissed.
I have tried to reproduce this simple layout also just using native Android, but it seems I don't have any similar bug. Is this a Xamarin Forms bug?
I am attaching the two sample projects. I have also put two buttons in the internal layout in order to increase or decrease its size so one can check easily the problem.
[Guide] Create a Gradient Background without Images
Hey,
today I accomplished the task to create Gradient Background without the use of an Image.
The task was to make it possible for the user to change the Background of the Views on Runtime! First I thought I could achive this with Images but on the long run it would have blown up the App-Size.
This is the best implementation I could come up with and the choosen Colors are persistent with the usage of the Settings Plugin form @JamesMontemagno that you can get here: Nuget
This code works for Android and iOS and you can drop it in if you want
So long Story short here's the code:
CustomRenderer in PCL
:
public class GradientContentPage : ContentPage
{
public static BindableProperty StartColorProperty = BindableProperty.Create<GradientContentPage, Color>(p => p.StartColor, Color.White);
public static BindableProperty EndColorProperty = BindableProperty.Create<GradientContentPage, Color>(p => p.EndColor, Color.Gray);
public Color StartColor
{
get { return (Color) GetValue(StartColorProperty); }
set { SetValue(StartColorProperty, value); }
}
public Color EndColor
{
get { return (Color) GetValue(EndColorProperty); }
set { SetValue(EndColorProperty, value); }
}
}
To make the Colors available all over my app I create two static variables in App.cs and since I can't put a Color
into the Settings I have to store them as string
So here's the code for my App.cs
public static Color StartColor;
public static Color EndColor;
public App()
{
StartColor = StringToColor(Helpers.Settings.StartColor.Split(' , ');
EndColor = StringToColor(Helpers.Settings.EndColor.Split(' , ');
MainPage = new NavigationPage(new DashboardView{ StartColor = App.StartColor, EndColor = App.EndColor });
}
As you may notice I've setting the Colors for the View on creation. Sadly you have to this, because Views that inherit from ContentPage
can't make us of Implicit Styles
right now because of this Bug 27659
So anyway let's take a look at StringToColor
private static void StringToColor(IList<string> color)
{
for(var i = 0; i < color.Count(); i++)
{
//Regex to get the color code
color[i] = Regex.Replace(color[i], @"^\d.\d+]", "");
}
var a = double.Parse(color[0], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
var r = double.Parse(color[1], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
var g = double.Parse(color[2], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
var b = double.Parse(color[3], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
return Color.FromRgba(r, g, b, a);
}
Ok, I admit I'm not happy with this function and if anyone has a better idea how to achive this, please let me know! Basically this function find the Color-Code.
Alright now let's get to the platform renderers:
CustomRenderer in Android
:
[assembly: ExportRenderer(typeof(GradientContentPage), typeof(GradientContentPageRenderer))]
namespace YourApp.Droid
{
public class GradientContentPageRenderer : PageRenderer
{
protected override void OnVisibilityChanged(Android.Views.View changedView, ViewStates visibility)
{
base.OnVisibilityChanged(changedView, visibility);
SetBackground();
}
protected override void OnElementChanged(ElementChangedEventArgs<Page> page)
{
base.OnElementChanged(page);
SetBackground();
}
private void SetBackground()
{
var startColor = App.StartColor.ToAndroid();
var endColor = App.EndColor.ToAndroid();
var colors = new int[] { startColor, endColor };
Background = new GradientDrawable(GradientDrawable.Orientation.TopBottom, colors);
}
}
}
You have to overwrite both Events to get every Background in the color you wan't. It's a bit odd but this is how Forms on Android reacts and there is no (at least I haven't found one) event that gets fired everytime you switch a Page;
CustomRenderer in iOS
:
[assembly: ExportRenderer(typeof(GradientContentPage), typeof(GradientContentPageRenderer))]
namespace YourApp.iOS
{
public class GradientContentPageRenderer: PageRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
var gradientLayer = new CAGradientLayer
{
Frame = View.Bounds,
Colors = new [] { App.StartColor.ToCGColor(), App.EndColor.ToCGColor() },
StartPoint = new CGPoint(0, 0),
EndPoint = new CGPoint(1, 1)
}
//This is needed to get every background redrawn if the color changes on runtime
if(View.Layer.Sublayers[0].GetType() == typeof(CAGradientLayer))
{
View.Layer.ReplaceSublayer(View.Layer.Sublayers[0], gradientLayer);
}
else
{
View.Layer.InsertSublayer(gradientLayer, 0);
}
}
}
}
For this one I have to thank @JohnBeans for his thread here on the forum: Click me
So for the Color Picking I created a view where the user can select a color and then it gets automatically drawn on runtime with the new color. But posting this would be to much for one thread. If someone is interested I can post it.
ListView Crash on WP
ListView Binded with ObservableCollection, if in viewCell I bind Style with StaticResource on WP Application Crash!
<ViewCell>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="1"></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
</Grid.RowDefinitions>
. . .
<Grid Grid.Row="1" >
<StackLayout Style="{StaticResource GreyBarStyle}"></StackLayout>
</Grid>
</Grid>
</ViewCell>
NB: on iOS it works
Is it possible to set a Title and Subtitle in the navigation bar on Android and iOS?
Is it possible to set a Title and subtitle in the navigation bar on Android and iOS?
I know I will have to use a custom navigation renderer for this. Possibly providing a custom view for the navigation bar.
But I have scoured the internet and haven't found anything that would help me do this.
Has anyone got any example or know how to do this?
Notification over a toolbar item
I want a notification on toolbar item. I developed this in android but in forms..? In android I added some xml files to the toolbar item.