- Is it possible to use custom ttf font in Xamarin.Forms pages for elements like icons in the action bar, etc? (FontAwesome ttf)
- How does ImageSource.FromResource method work? Does it handle multiple resolutions and dpi settings? How should I use it?
Custom Font in Xamarin.Forms (Font Awesome)
Problem with the resume of my app.
Hello,
I post here because I have a bug with my Xamarin.Forms application. I think I have some problems because of the onResume() portion of code with the Android part. (In the MainActivity.cs file)
When I leave my app with the back button, or when I open it from the notification center (because my app sometimes send notifications),
the application opens correctly but my Google Map is not properly loaded and the color on my slider (which should be a color gradient) becomes grey.
With this problem, my map doesn't properly load, and the geolocator fail to focus the map on my position.
The problem is not present when I leave the app from the "Home" button. I guess that it comes from the onResume() because of the android activity lifecycle. I'll paste the MainActivity.cs file if someone could help me with this It would help me a lot.
I don't know what to add in the onResume() portion of code to make it load properly.
Thanks for helping !
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
App.androidActivity = this;
// Facebook initialisation
FacebookSdk.SdkInitialize(this.ApplicationContext);
// Creation of facebook callback manager
callbackManager = CallbackManagerFactory.Create();
// Definition of callbacks for Xamarin :O
LoginManager.Instance.RegisterCallback (callbackManager, this);
// Preparing the login manager actions
MessagingCenter.Subscribe<object> (this, "LoginWithReadPermissionsInFacebook", (sender) => {
LoginManager.Instance.LogInWithReadPermissions(this, new List<string>{"public_profile","user_friends"});
});
MessagingCenter.Subscribe<object> (this, "LogOutFromFacebook", (sender) => {
LoginManager.Instance.LogOut();
});
// Init of Xlabs :)
DependencyService.Register<Geolocator> ();
// Init of Xamarin
global::Xamarin.Forms.Forms.Init (this, bundle);
Xamarin.FormsMaps.Init (this, bundle);
Forms.SetTitleBarVisibility (AndroidTitleBarVisibility.Never);
LoadApplication (new App());
}
public override void OnBackPressed()
{
if(OutMySphere.App.IsLoggedIn() && AccessToken.CurrentAccessToken != null && Profile.CurrentProfile != null)
base.OnBackPressed();
}
protected override void OnResume()
{
base.OnResume ();
}
public void OnCancel()
{
MessagingCenter.Send<object> (this, "AccessDenied");
}
public void OnError(FacebookException error)
{
MessagingCenter.Send<object> (this, "AccessDenied");
}
public void OnSuccess(Java.Lang.Object result)
{
MessagingCenter.Send<object> (this, "FacebookLoginSuccess");
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult (requestCode, resultCode, data);
callbackManager.OnActivityResult (requestCode, (int)resultCode, data);
}
}
Using the XLabs CarouselView Control
I'm trying to make a simple image carousel but am unable to get anything to display. I have tested the DataTemplate with the Xlabs RepeaterView and the Xamarin ListView with the same ViewModel and bindings to confirm that those are correct. Here is the code:
XLabs.Forms.Controls.CarouselView<Photo> carousel = new XLabs.Forms.Controls.CarouselView<Photo>
{
TemplateSelector = new TemplateSelector
{
Templates = new DataTemplateCollection
{
new DataTemplateWrapper<Photo>{
IsDefault = true,
WrappedTemplate = new DataTemplate(()=>
{
var l = new StackLayout();
l.BackgroundColor = Color.FromHex("#f2f2f2"); // added a background color to see if a stacklayout would be displayed. It isn't
Image image = new Image
{
Aspect = Aspect.AspectFill,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
image.SetBinding<Photo>(Image.SourceProperty, (ph) => ph.ImageSource);
l.Children.Add(image);
return l;
})
}
}
}
};
carousel.SetBinding(XLabs.Forms.Controls.CarouselView<Photo>.ViewModelsProperty, "Photos");`
The difference between this and the Repeater/ListView controls appears to be the TemplateSelector and TemplateWrapper properties, so perhaps I'm doing something wrong there. There is a CarouselSample here in XAML: https://github.com/XLabs/Xamarin-Forms-Labs/tree/master/Samples/XLabs.Sample/Pages/Controls but I can't see anything that I'm missing off-hand.
can'r run xamarin forms on my studio
Hello,
recently I downloaded the visual 2015 with xamarin for a new project that I wanted to build using xamarin forms.
In the very first running I got an error- The type or namespace name 'App' does not exist in the namespace App1'' (are you missing an assembly reference?)
I googled a lot and found a bugzila fix- https://bugzilla.xamarin.com/show_bug.cgi?id=32622
And did the fix, (replacing the files- Xamarin.Android.Common.targets and Xamarin.IOS.Common.targets).
But now I get a new problem-
Severity Code Description Project File Line Suppression State
Error The "Xamarin.Android.Tasks.AddTrialSplashScreenResources" task could not be loaded from the assembly C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. App1.Droid
And I just can't find solution for it.
How can I run the project?
Thanks!
Telerik listview item appearing
ListView listview = new ListView()
{
ItemsSource = abc,
};
listview.ItemAppearing += (sender, e) =>
{
var items = ((ListView)sender).ItemsSource as IList;
if (items != null && e.Item == items[items.Count - 4])
{
//Load more items here
}
};
I'm working on xamarin forms using listview like this its working perfect but when i'm using telerik radlistview not appearing not exist event ItemAppearing event. please help me
thanks in advance.
Switch color for Xamarin Forms
How do I change the swich color in xamarin forms because in Android I see different color in Lollipop itself, Is this the issue in xamarin forms or I can shange using any renderer please suggest asolution?
Can i enable/disable the system keyboard in PCL?
I'm new on Xamarin Forms, I wanted to enable/disable the default keyboard when you focus an Entry. I have a custom keyboard in my sample-app so i don't need it. I tried entry1.Keyboard = null but it doesn't work. Is there any solution?
Is invalidating layout supposed to cause an immediate layout pass?
I've read Petzold's book chapter about custom layouts a few times, and written some successful custom layouts for our application. But as I was working on it, I noticed a few things that seem to lead to redundant layout passes. I can't figure out how these fit in with what I thought I understood about the layout system.
I've attached an example page (As text, for some reason it claimed .cs is not allowed.) in which I've placed a Grid that contains a label and a button. Clicking the button removes the label and replaces it with a new one. This is similar to something I'm doing in my application. I'd expect a program run to show this:
- Removing the label.
- Removed!
- Adding the label.
- Added!
- Page is laying out.
- Grid is laying out.
- Label size is allocated.
What I actually see is this:
- Removing the label.
- Page is laying out.
- Grid is laying out.
- The label is removed.
- Adding the label.
- Page is laying out.
- Grid is laying out.
- Label size is allocated.
- Added!
It appears that adding or removing children to the Grid (and all layouts) immediately causes them to lay out completely. This causes problems in my custom layouts, or at least requires me to develop them more carefully so I don't redo expensive calculations too many times. It really kills me on page rotations, where some of what I do can cause up to 6 layout passes across several nested layouts. Caching isn't really an option, because many of my elements change sizes frequently based on incoming GPS data and other sources. This isn't what I expected.
My understanding is manipulating children should cause Grid to call InvalidateLayout(). Intuitively, I expected that to work like invalidation in Windows, where a message is added to an internal message queue and combined so multiple invalidations result in only one redraw. Xamarin Forms seems to treat layout invalidation as a queue to immediately perform a new layout pass. Is this the expected behavior?
Setting ringtone from mp3 in asset folder
Hi,
I am using Xamarin Forms and using Dependency Service to set ringtone from mp3 places in asset folder. Here is my code:
AssetManager assets = Forms.Context.Assets;
fileName = "Artist.mp3";
System.IO.Stream inputStream;
System.IO.Stream outputStream;
try
{
inputStream = assets.Open("Sounds/" + fileName);
**_ outputStream = Forms.Context.OpenFileOutput(fileName, FileCreationMode.Private); _**
byte[] buffer = new byte[65536 * 2];
int read;
while ((read = inputStream.Read(buffer, 0, (int)inputStream.Length)) != -1)
{
outputStream.Write(buffer, 0, read);
}
inputStream.Close();
inputStream = null;
outputStream.Flush();
outputStream.Close();
outputStream = null;
Java.IO.File newSoundFile = new Java.IO.File(basepath + "/Sounds/" + fileName);
if (newSoundFile.Exists())
{
ContentValues values = new ContentValues();
values.Put(MediaStore.MediaColumns.Data, newSoundFile.AbsolutePath);
values.Put(MediaStore.MediaColumns.Title, "Test Ringtone");
values.Put(MediaStore.MediaColumns.MimeType, "audio/*");
values.Put(MediaStore.MediaColumns.Size, newSoundFile.Length());
values.Put(MediaStore.Audio.Media.InterfaceConsts.Artist, "Artist MP3");
values.Put(MediaStore.Audio.Media.InterfaceConsts.Duration, 2300);
values.Put(MediaStore.Audio.Media.InterfaceConsts.IsRingtone, true);
values.Put(MediaStore.Audio.Media.InterfaceConsts.IsNotification, false);
values.Put(MediaStore.Audio.Media.InterfaceConsts.IsAlarm, false);
values.Put(MediaStore.Audio.Media.InterfaceConsts.IsMusic, false);
Android.Net.Uri uri = MediaStore.Audio.Media.GetContentUriForPath(newSoundFile.AbsolutePath);
Forms.Context.ContentResolver.Delete(uri, MediaStore.MediaColumns.Data + "=\"" + newSoundFile.AbsolutePath + "\"", null);
Android.Net.Uri newUri = Forms.Context.ContentResolver.Insert(uri, values);
try
{
RingtoneManager.SetActualDefaultRingtoneUri(Forms.Context, RingtoneType.Ringtone, newUri);
}
catch (Exception e)
{
}
}
}
catch (Exception e)
{
}
I am getting below exception in the bold and underlined line in above code.
System.NotSupportedException: Specified method is not supported.
at Android.Runtime.InputStreamInvoker.get_Length () [0x00000] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/src/Runtime/InputStreamInvoker.cs:55
LayoutChildIntoBoundingRegion Z-index/order of children
I'm working on making our app more efficient, and have some user controls/views that I'm now going back and overriding LayoutChildren since we know exactly where we want each element. It seems that I can't use LayoutChildIntoBoundingRegion to overlay one element on top of the other.
As a simple test I've got a BoxView and a Label. I would expect that if I first call LayoutChildIntoBoundingRegion on the BoxView, and then call it on the label, putting the label in a position over top of the BoxView I'd end up with a nice overlay, without having to add a grid or absolute view into the mix. End result though is I'm only seeing the BoxView. If I comment out the BoxView the Label is displayed in the correct place where it should be on top of the box. Swapping the order I do LayoutChildIntoBoundingRegion in the code doesn't help (as expected).
Is this working as designed, so I'll need to go back to the grid to get an overlay?
Share code behind between two different XAML presentations?
I have an app that I need to rearrange the UI extensively to make the UI efficient between iPad Mini and iPhone so is it possible to connect two different XAML layouts to one code behind since only the presentation would be different?
I have tried using OnIdiom but the changes are quite extensive and it gets really ugly ......
Webview open external browser
Hello all,
i'm using xamarin.forms webview to open a html page. So far so good.
Inside my html has "a href" linking to another URL and when clicked, its open inside the webview. I wanna open outside the webveiw, using the external browser (device broser). Any ideia?
Thanks a lot
Anyway to GetBinding()?
I need to do validation based upon ValidationAttribute but I cant seem to get the bindings. Basically the idea is to write a behavior that can interrogate the property of the model set to the control. So say the Text property binding, grab its property's validationattributes and then set the tint to red if it invalid. The problem being, I cant see the private bindings list. How can I grab the bindings like the SetBinding, only have a GetBinding? And why are the properties private?
EDIT: To be more specific can we open up BindablePropertyContext to public as well as GetContext? Or make another function to give back the BindablePropertyContext?
Thanks!
Why label value not updating in custom ViewCell
Hi, I've got this simple custom ViewCell below with a Text property to display the item text in a label. I want to set this in xaml however the value never appears. I'm sure I'm doing something dumb here, can anyone point it out?
Thanks!
XAML:
<customViews:MainMenuItemCell Text="item text" Command="{Binding TappedCommand}"/>
Custom ViewCell class:
public class MainMenuItemCell : ViewCell
{
public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(MainMenuItemCell));
public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string),typeof(MainMenuItemCell),null,BindingMode.TwoWay);
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public MainMenuItemCell()
{
var viewLayout = new Grid();
viewLayout.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)});
var label = new Label
{
Text = Text,
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center
};
Grid.SetRow(label,0);
Grid.SetColumn(label,0);
viewLayout.Children.Add(label);
var gestureRecognizer = new TapGestureRecognizer();
gestureRecognizer.Tapped += (s, e) =>
{
if (Command != null && Command.CanExecute(null))
{
Command.Execute(s);
}
};
// binding can be set here or in xaml
//SetBinding(CommandProperty, new Binding("ItemSelectedCommand"));
viewLayout.GestureRecognizers.Add(gestureRecognizer);
View = viewLayout;
}
}
say for chamarin and transform for text
Hi,
How to say for xamarin and transform speak on text?
Could not generate Release build
Hi,
I could not generate release build for my xamarin.forms android app.
I am getting following error, can some one help me out with this ?
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(5,5): Error MSB4018: The "LinkAssemblies" task failed unexpectedly.
Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'Xamarin.Forms.BindableProperty Xamarin.Forms.BindableProperty:
:Create(System.Linq.Expressions.Expression1<System.Func
2<!!0,!!1>>,!!1,Xamarin.Forms.BindingMode,Xamarin.Forms.BindableProperty/ValidateValueDelegate
1<!!1>,
Xamarin.Forms.BindableProperty/BindingPropertyChangedDelegate
1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangingDelegate1<!!1>,Xamarin.Forms.
BindableProperty/CoerceValueDelegate
1<!!1>)' (defined in 'Xamarin.Forms.Labs, Version=1.0.1.5, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Labs, Version=1.0.1.5, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve Xamarin.Forms.BindableProperty
Xamarin.Forms.BindableProperty::Create(System.Linq.Expressions.Expression
1<System.Func
2<!!0,!!1>>,!!1,Xamarin.Forms.BindingMode,Xamarin.Forms.BindableProperty/ValidateValueDelegate
1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangedDelegate
1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangingDelegate1<!!1>
,Xamarin.Forms.BindableProperty/CoerceValueDelegate
1<!!1>)at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute()
--- End of inner exception stack trace ---
at Xamarin.Android.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args)
at Xamarin.Android.Tasks.LinkAssemblies.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__1.MoveNext() (MSB4018) (AlmaraiFormsApp.Droid)
Companies that make controls for forms?
@ThomasBurkhart pointed to a company that does very nice graph controls for XF (and free for small companies).
https://www.syncfusion.com/products/xamarin/chart
It got me thinking, what other companies are out their selling XF controls? I don't like spending time on custom renderers for fancy controls, I'm happy to pay for code that saves me time. What other companies are out there??
Specifying ContentPage BackgroundImage with a Style and using xcassets
I'm using images.xcassets for my iOS application, for my AppIcon and LaunchImage.
I now need to specify a background image for all my ContentPages, and want to do so using a Style. To this end I've got a style:
<Style
TargetType="ContentPage">
<Setter
Property="BackgroundImage"
Value ="BackgroundImage" />
</Style>
defined in my App.xaml.
I've created a new Image Set called BackgroundImage in my Images.xcassets, and have used the Asset Catalog Creator to create BackgroundImage.png, BackgroundImage@2x.png and BackgroundImage@3x.png and have added these to the BackgroundImage Image Set.
However, I'm not seeing the background image when I run the app.
Any suggestions/hints please?
How to dynamically load a content page?
How to dynamically load a content page from a string (xaml)? Not to create a lot of similar pages.
eg
var page = new ContentPage()
string xaml = ...
page.LoadFromXaml(xaml)
how take picture multiple??? :(
how .. multiple button take a picture ; ;