Hello!!
I have a problem with my customize data template selector.
When I register to this event: content.BindingContextChanged += OnBindingContextChanged;
it cause a memory leak in the app and after few minutes the app flies.
If there is event unsubscribe please let me know where is the right place to put it.
Data template selector memory leak
how to add reference Xamarin.Forms.Core
I am new to Xamarin. I wanted to see some working project, so I downloaded some projects from Github. I cannot build them, because the reference to "Xamarin.Forms.Core" and "Xamarin.Forms.Platform.IOS" is displayed with a yellow triangle and I am getting messages like
Error CS0234 The type or namespace name 'Platform' does not exist in the namespace 'Xamarin.Forms' (are you missing an assembly reference?) DrawIt.Android H:\f13\Drawit\DrawIt\DrawIt.Android\ImageWithTouchRenderer.cs 3 Active
Thanks
Vaclav
How can I use binding with static property ?
I am using this code but its not working :
IsVisible="{x:Static local:GlobalResources.IsUserLoggedIn}"
This is the class :
public class GlobalResources
{
public static bool IsUserLoggedIn { get; set; }
}
Xamarin xaml forms with FreshMvvm and using multiple IOC registration
Hi I am working with FreshMvvm and I can put multiple table in one data service and registered on single IOC but I need to do it in way that I can have separation IOC's for tables?
Is there any example method available?
Kind Regards,
Rahul
Button with image
Hi all,
I need an urgent help please. I am trying to have a button with an image. Actually I simple want to show he image and have it behave as a button. I have created the button and gave it a widthrequest of 120 and Heightrequest of 120 also. I then placed an image of size 120x120. But the image does not get aligned with the button. It shifts somehow showing some parts of the button. How do I make the image alight exactly with the button.
Here's the code
Button btn = new Button
{
WidthRequest = 120,
HeightRequest = 120,
Image = "btnResults.jpg",
};
iOS project : FileNotFoundException on Host invalid path
Hi all,
I develop a cross-platform app using Visual Studio 2015 and build iOS app using an host.
The build failed with this exception :
System.IO.FileNotFoundException: /Users/admin/Library/Caches/Xamarin/mtbs/builds/TeedlMobileiOS/44a299393b33183ffe81e6e2cebbc7ad/obj/iPhoneSimulator/Debug/Images/Calendar/datecell.png does not exist
When I check on my mac, I see that this image is called "Images\Calendar\datecell.png" and its path is "/Users/admin/Library/Caches/Xamarin/mtbs/builds/TeedlMobileiOS/44a299393b33183ffe81e6e2cebbc7ad/obj/iPhoneSimulator/Debug/Images\Calendar\datecell.png"
The path is not correctly set and it's the same issue for all images of Calendar, Checkbox and Radiobutton folders.
How can I fix it please ? Thanks in advance.
I use Xamarin.Forms v2.2.0.5-pre2 but not Toasts.Forms.Plugin (I saw during my search on google that the same issue can happen)
Using x:Reference from inside a DataTemplate stored in another XAML file
hello,
so I have a app using Prism as my MVVM engine and one of the pages is a MasterDetail page in which the details page part looks like this
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<StackLayout Padding="10, 0, 0, 0">
<ListView x:Name="listView" IsPullToRefreshEnabled="False" CachingStrategy="RecycleElement"
ItemsSource="{Binding Products}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnItemTapped"
Command="{Binding Source={x:Reference listView}, Path=BindingContext.ClickProductTreeCommand}"
CommandParameter="{Binding}"/>
</StackLayout.GestureRecognizers>
<StackLayout.Padding>
<OnPlatform x:TypeArguments="Thickness"
iOS="5,0,0,0"/>
</StackLayout.Padding>
<Label FontSize="Medium" FontAttributes="Bold" VerticalOptions="CenterAndExpand" HorizontalOptions="Start"
Text="{Binding Name}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
everything works fine, but now it has come up that some list view items will need an extra label and a button so I decided to update to XF 2.1.0 pre 5 and test the new DataTemplateSelector they just introduced, so I made all the necessary arrangements and made the C# class and two new xaml files with the appropriate data templates, the above one looks like so:
<?xml version="1.0" encoding="utf-8" ?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestApp.Views.MenuItemCellTemplate">
<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={x:Reference listView}, Path=BindingContext.ClickProductTreeCommand}"
CommandParameter="{Binding}"/>
</StackLayout.GestureRecognizers>
<StackLayout.Padding>
<OnPlatform x:TypeArguments="Thickness"
iOS="5,0,0,0"/>
</StackLayout.Padding>
<Label FontSize="Medium" FontAttributes="Bold" VerticalOptions="CenterAndExpand" HorizontalOptions="Start"
Text="{Binding Name}"/>
</StackLayout>
</ViewCell>
and the MasterDetail page now looks like:
...
<ListView x:Name="listView" IsPullToRefreshEnabled="False" CachingStrategy="RecycleElement"
ItemsSource="{Binding Products}">
<ListView.ItemTemplate>
<template:ProductMenuDataTemplateSelector/>
</ListView.ItemTemplate>
</ListView>
...
but now I get an error when I get to this page :
System.Exception: Can't resolve name on Element
so my guess was automatically that it cannot find the x:Reference part namely the listView element, and so I commented the TapGestureRecognizer part of the code to test my theory and apparently I was right, with that piece of code commented out there is no error anymore but also I don't have the command implemented
so my question is how can I access the command in the MasterDetail viewmodel as clearly the x:Reference does not work in this situation and I don't think there is an implementation of a AncestorType in XF at this time, also pondering on this problem I have another question: if I had the master and detail pages in different XAML pages how could they access the viewmodel from the MasterDetail page ?
thank you in advance for any ideeas
Animation.Commit()
What are the meaning of the "rate" and "length" parameters?
I am trying to have a method auto redraw my view every minute using the following code
updateNow = new Animation(t => {
Invalidate();
});
updateNow.Commit(this, "UpdateNow", repeat: () => true, rate: 60 * 1000, length: 60 * 1000); // refresh the arrow every minute
But the animation callback is called very often (probably every second or something...)
How to build Pin pattern password using xamarin form?
I am trying to create a pin pattern password screen. I was wondering what is the best way to develop this using Xamarin forms. I have looked into the documentation , but did not help me . Any pointers highly appreciated.
Changing Height from ViewRenderer
Hi All,
I have an issue with a ViewRenderer. I want to change the height of the view from my custom renderer.
Below is my code. I have simplified it for illustration:
public class MyRenderer: ViewRenderer<Xamarin.Forms.View, Android.Views.View>
{
private int m_height = 80;
public override SizeRequest GetDesiredSize(int widthConstraint, int heightConstraint)
{
var sizeRequest = base.GetDesiredSize(widthConstraint, heightConstraint);
sizeRequest.Request = new Size(sizeRequest.Request.Width, m_height);
return sizeRequest;
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
{
base.OnElementChanged(e);
if(this.Control == null)
{
var v = new Android.Views.View(this.Context);
this.SetNativeControl(v);
v.Click += (s, evt) =>
{
m_height = 400;
this.RequestLayout();
};
}
}
}
When the control is shown for the first time, the method GetDesiredSize is called and the height (m_height) to the control is set. This is working as I expect.
Then, when I click over the View, I want to change its height to 400 for example and then I call RequestLayout but there is no effect at all.
Can anyone please assist me on how to accomplish this?
Thanks in advance and best regards,
Fabian von Romberg
Is this possible - a master-detail page with navigation within the Master view?
I'm implementing a file-browser type app using a MasterDetailPage as the main view.
The detail page shows the contents of a file.
The master page (which derives from NavigationPage) shows either a list of files within a folder, or the list of folders. Folders do not nest, to it simple.
The app starts with the master view first pushing the folder view and then the list of the files within the "default" folder.
Therefore, the user can click on a file to show its contents in the detail view. Or, the user can click "Back" to see in the master view the list of all folders.
This structure works on the UWP desktop where there is a "Back" button and the master view is visible by default.
However, on UWP mobile, only the detail view is present at startup, which is initially empty, and there is no back button. So the user sees just a blank page, with nowhere to go!
So I'm wondering what the right way is to structure the views, so that this simple file browser works intuitively on all platforms.
Thoughts?
Master/Detail with Navigation Page has issues...
I have a setup where I first display a login page, then switch to a master-detail view for the "main" part of the application. Here's what's happening.
I begin the application by creating a NavigationPage:
public static Page GetMainPage()
{
return new NavigationPage( new LoginPage );
}
After the user successfully logs in, I call Navigation.PushAsync( masterDetailPage );
to show the new interface.
1) On iOS this works, but I have to call NavigationPage.SetHasNavigationBar( masterDetailPage, false );
first, or I get the nav bar with a Back button on top of the masterDetailPage header.
2) On Windows Phone, the default Detail page shows, but the header is not there, and no way to bring up the Master/menu view.
3) It crashes on Android.
So, to make sure I was doing this properly, I changed GetMainPage to simply use the Master/Detail page:
public static Page GetMainPage()
{
return new MyMasterDetailPage();
}
This worked as expected on all three platforms.
I then tried using the Master/Detail as the root of the NavigationPage:
public static Page GetMainPage()
{
return new NavigationPage( new MyMasterDetailPage() );
}
This works on iOS and Windows Phone. On Android, it crashes. For my final test:
public static Page GetMainPage()
{
NavigationPage _navPage = new NavigationPage( new MyMasterDetailPage() );
_navPage.PushAsync( new LoginPage() );
return _navPage;
}
Then, upon successful login, simply call Navigation.PopAsync();
to show the Master/Detail view.
1) On iOS this works, but the Master/Detail page is shifted down the screen by the height of the navigation bar.
2) On Windows Phone, the Master/Detail header (footer?) is there all the time, even on the LoginPage.
3) On Android, the Master/Detail page is missing the header bar, so no way to get to the Master panel.
This is all incredibly frustrating, to say the least.
Know if a control is on screen
How do I know if a control is displayed?
For now I am gonna use the code below, but wonder if there is a more efficient way?
Cumbersome code that should do the trick (improvement needed!!):
public class VisibilityObserver
{
List<VisualElement> hierarchy;
public VisibilityObserver()
{
}
public VisibilityObserver(Element target)
{
Target = target;
}
#region GetHierarchy()
static List<VisualElement> GetHierarchy(Element e)
{
var result = new List<VisualElement>();
while (e != null)
{
var ve = e as VisualElement;
if (ve != null)
result.Add(ve);
e = e.Parent;
}
return result;
}
#endregion
#region List() Unlisten()
void Listen(List<VisualElement> visuals)
{
if (visuals == null)
return;
foreach (var ve in visuals)
{
ve.PropertyChanged += Ve_PropertyChanged;
ve.SizeChanged += Ve_SizeChanged;
ve.ChildRemoved += Ve_ChildRemoved;
ve.DescendantRemoved += Ve_DescendantRemoved;
}
}
void Unlisten(List<VisualElement> visuals)
{
if (visuals == null)
return;
foreach (var ve in visuals)
{
ve.PropertyChanged -= Ve_PropertyChanged;
ve.SizeChanged -= Ve_SizeChanged;
ve.ChildRemoved -= Ve_ChildRemoved;
ve.DescendantRemoved -= Ve_DescendantRemoved;
}
}
private void Ve_DescendantRemoved(object sender, ElementEventArgs e)
{
UpdateHierachy();
}
private void Ve_ChildRemoved(object sender, ElementEventArgs e)
{
UpdateHierachy();
}
private void Ve_SizeChanged(object sender, EventArgs e)
{
UpdateVisible();
}
private void Ve_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == null || e.PropertyName == nameof(VisualElement.Parent)) { UpdateHierachy(); }
else if (e.PropertyName == null || e.PropertyName == nameof(VisualElement.IsVisible)) { UpdateVisible(); }
}
#endregion
#region UpdateHierachy() UpdateVisible()
void UpdateHierachy()
{
Unlisten(hierarchy);
hierarchy = GetHierarchy(Target);
Listen(hierarchy);
UpdateVisible();
}
void UpdateVisible()
{
if (hierarchy == null || hierarchy.Count == 0)
{
IsVisible = false;
}
else
{
foreach (var item in hierarchy)
{
if (!item.IsVisible || item.Width <= 0 || item.Height <= 0)
{
IsVisible = false;
return;
}
}
IsVisible = hierarchy.Last() is Page;
}
}
#endregion
#region IsVisible IsVisibleChanged
public bool IsVisible
{
get { return mIsVisible; }
private set
{
if (value == mIsVisible)
return;
mIsVisible = value;
IsVisibleChanged?.Invoke(this, EventArgs.Empty);
}
}
bool mIsVisible;
public event EventHandler IsVisibleChanged;
#endregion
#region Target
public Element Target
{
get { return target; }
set
{
if (value == target)
return;
target = value;
UpdateHierachy();
}
}
Element target;
#endregion
}
Basic Number Picker Control?
Hi,
I'm looking for a 'picker' type control that will do number selection - ie set max and min values, number of decimal places and you can pick a number using a 'wheel' type interface rather than by typing text into a text field. Is there anything like that out there?
cheers
Release 2.2.0.31, Winphone error on launching new blank project !
After creating a blank portable project (Xamarin Portable) with Visual Studio 2015 and updating to Xamarin.Forms release 2.2.0.31, it runs on various Winphone simulators (Emulator 8.1 WVGA 4 inch, Mobile Emulator 10.0.10240.0 ...) but when I am trying to run it on a real device WinPhone 8.1 (8.10.14234.375) or WinPhone 10 (10.0.10586.218) it fails with an error on the Xamarin.Forms.Forms.Init(e) method, inside the App.OnLaunched(LaunchActivatedEventArgs e) override !
The error is :
System.Runtime.InteropServices.COMException was unhandled by user code
ErrorCode=-2147467259
HResult=-2147467259
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=Windows
StackTrace:
at Windows.UI.Xaml.ResourceDictionary.put_Source(Uri value)
at Xamarin.Forms.Forms.GetPhoneResources()
at Xamarin.Forms.Forms.Init(IActivatedEventArgs launchActivatedEventArgs)
at XamarinPortable.WinPhone.App.OnLaunched(LaunchActivatedEventArgs e)
InnerException:
Previously with release 2.0.0.31 all was correct ! Do I have to modify the Xamarin initialization for running on Winphone devices ?
Replacement of MainPage shows white row
Hi all!
I have a problem with MainPage: it's set to NavigationPage, but then I replace it with a ContentPage and see white row at bottom. I've already tried ForceLayout() and it didn't help.
Any suggestions?
RGB Color Identifier Using Camera
Hi,
I have requirement from Client using Camera i have to scan a color and display color code, I have searched in xamarin blog but could not get any help or links, Below are the sample play store apps which suits my requirement.
https://play.google.com/store/apps/details?id=com.mobialia.colordetector&hl=en
https://play.google.com/store/apps/details?id=com.loomatix.colorgrab&hl=en
Thanks,
Pranay Chandra Sapa
how to get checkbox control in list of items
i am using xamarin form i want to check uncheck list of item then add them to cart
WebException : Send Failure. Error Writing Headers
I am trying to read some data from a local https server using HttpClient. The code works OK for HTTP. The Exception which is thrown with HTTPS is
System.Net.WebException : Send Failure. Error Writing Headers
var client = new System.Net.Http.HttpClient();
client.BaseAddress = new Uri("https://192.168.12.15/");
var response = await client.GetAsync("json.php");
var retdata = response.Content.ReadAsStringAsync ().Result;
I don't want to jump the gun here, but I happen to know that the certificate offered by the web server may fail validity checks because it has been self signed. If it is related to this is it possible to add a callback to allow prevent the certificate being rejected. When I try to access the URL from Safari the page is served, but only after I have accepted certificate warnings.
However.....the problem may not even be related to the certificate, can anyone comment?
Thanks.
How do i create a pop-up content page on some action?
public SettingsPage()
{
InitializeComponent();
var tapGestureRecognizer_imageid = new TapGestureRecognizer();
tapGestureRecognizer_imageid.Tapped += (s, e) => {
Navigation.PushAsync(new PopUpPage());
};
accountid.GestureRecognizers.Add(tapGestureRecognizer_imageid);
accountsettings.GestureRecognizers.Add(tapGestureRecognizer_imageid);
}
I want a Pop-up content page when i tap that action