I set the LaunchScreen.storyboard but the app not refreshed
need I do something else?
I set the LaunchScreen.storyboard but the app not refreshed
need I do something else?
The application I'm currently working on requires data to be retrieved from a web service during app startup that roughly takes 1.5 seconds. After the data is retrieved, it needs to be displayed on the MainPage and that is another 1.5 - 2 seconds since the data is mostly URLs of images that have to be displayed, in my case, using ffimageloading library; which means actually downloading those images first to be displayed. I have splash startup screens for both Android and iOS implemented separately in platform projects but splash screen only stays up for the amount of time Xamarin Forms needs to load and afterwards disappears not waiting for my actual model to load from the web service. I have searched for solutions to extend the splash screen duration and mostly every solution I have read involves creating another splash screen page, loading page if you will, that is already controlled in PCL project but having two separate splash loading screens just seams not feasible for me at the moment. So I was wondering, how would one load the initial model in platform projects, during the actual splash screen, and then later pass it to PCL project when Xamarin Forms has finished initialization, presumably to App.xaml.cs 's App() constructor function?
Hey guys,
I'm trying to work with native controls in Xamarin.Forms, but I get the following exception when trying to reference Xamarin.Forms.Platform.iOS:
The type or namespace name 'iOS' does not exist in the namespace 'Xamarin.Forms.Platform' (are you missing an assembly reference?)
Because of this I'm not able to use the .ToView() extension method.
This is my code:
using System; using UIKit; using Xamarin.Forms.Platform.iOS; using Xamarin.Forms; namespace AppName { public class MyPage : ContentPage { public MyPage() { View view = null; UILabel label = new UILabel { Text = "Hello iOS Native!", Font = UIFont.FromName("Papyrus", 32f), }; view = label.ToView(); Content = view; } } }
Xamarin.Forms version: 4.5.0.495
These are the docs I'm working from: https://docs.microsoft.com/en-us/archive/msdn-magazine/2016/connect/mobile-embedding-native-views-in-your-xamarin-forms-apps
Do any of you know what's going on? I would really appreciate if you could help me out! Thanks in advance!
I tried implementing the BlinkID using Xamarin.Forms. However when I run the a project from iOS, it generates an error.
I did set the Linker behavior to "Link All".
When I comment out the initialization code for BlinkID in FinishedLaunching it compiles.
Code below
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { //Xamarin.Forms.DependencyService.Register<Microblink.Forms.iOS.MicroblinkScannerFactoryImplementation>(); global::Xamarin.Forms.Forms.Init(); LoadApplication(new App()); return base.FinishedLaunching(app, options); }
It works well in Android but not in iOS.
The error message I get talks about MTouch, when I uncomment this line Xamarin.Forms.DependencyService.Register<Microblink.Forms.iOS.MicroblinkScannerFactoryImplementation>();
Any Ideas anyone?
This crash happens while switching between applications.
mono.java.lang.RunnableImplementor.run
RunnableImplementor.java, line 30
Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown
Hi, I have somtehing like calendar, this calendar loads on button click, but after this click I want to scroll this calendar to the end of this loaded list, but it doesnt update, and if I had 20 items i still have 20 not 27. I have 27 after next click.
if (calender.ScrollX < 10 && CrossConnectivity.Current.IsConnected) { var position = calender.ScrollX; var Length = calender.ContentSize.Width; var viewModel = (CalendarViewModel)BindingContext; if (viewModel.LoadLeftList.CanExecute(null)) { await Task.Run(() => viewModel.LoadLeftList.Execute(null)); } var lastStack = (StackLayout)calendarStackList.Children[0]; await calender.ScrollToAsync(lastStack, ScrollToPosition.Start, false); var mainStackDate = (StackLayout)calendarStackList.Children[_indexOfFrame + MainConsts.GetNumberOfDates]; var mainFrame = (Frame)mainStackDate.Children.First(); mainFrame.BackgroundColor = Color.FromHex("#4074DD"); _lastClickedFrame = mainFrame; }
private async void LeftList() { if (!CrossConnectivity.Current.IsConnected) { return; } try { var datesSet = await MeetingService.GetMeetingsStatusesForDays(new GetMeetingsStatusesForDaysApi { Date = CalendarDates.First().EntireDate, Days = MainConsts.GetNumberOfDates, GetDateType = GetDateType.Left }); CalendarDates = datesSet.Concat(CalendarDates).ToList(); RaisePropertyChanged(nameof(CalendarDates)); } catch (Exception e) { await LogService.LogAsync(e); } }
So if you can see await Task.Run(() => viewModel.LoadLeftList.Execute(null));
this loads my list, but calendarStackList.Children
is still same number, how to handle this ?
I'm using Xamain.Forms version 4.5.0.356.
Any suggestion on how to solve this?
Thanks in advance.
i am using xf and dependecy injector to list and buy itens on my app...
but the event OnProductPurchased are not calling when i buy a item..
how to solve this?
my code:
public void EfetuaCompra(string produtoID) { var tas = _serviceConnection.BillingHandler.QueryInventoryAsync(new List<string> { "backup_online", ReservedTestProductIDs.Purchased, ReservedTestProductIDs.Canceled, ReservedTestProductIDs.Refunded, ReservedTestProductIDs.Unavailable }, ItemType.Product); tas.Wait(); IList<Product> _products = tas.Result; var produtoCompra = _products.Where(a => a.ProductId == produtoID).FirstOrDefault(); _serviceConnection.BillingHandler.OnProductPurchased += (response, purchase, purchaseData, purchaseSignature) => { Xamarin.Forms.Application.Current.Properties.Add("backup_comprado", "Comprado"); if (OnCompraEfetuadaSucesso != null) OnCompraEfetuadaSucesso(); }; _serviceConnection.BillingHandler.OnProductPurchasedError += (int responseCode, string sku) => { Console.WriteLine("Error purchasing item {0}", sku); }; _serviceConnection.BillingHandler.OnGetProductsError += (int responseCode, Bundle ownedItems) => { Console.WriteLine("Error getting products"); }; _serviceConnection.BillingHandler.OnPurchaseConsumedError += (int responseCode, string token) => { Console.WriteLine("Error consuming previous purchase"); }; _serviceConnection.BillingHandler.InAppBillingProcesingError += (message) => { Console.WriteLine("In app billing processing error {0}", message); }; _serviceConnection.BillingHandler.BuyProduct(produtoCompra); }
Good afternoon! How are you all?
I've been trying to implement a splash screen all day following tutorials here and there. The most common solution I found was to have a XML file in the drawable folder and call a bitmap from there. It was working fine until I tried to add a different splash for landscape. It all went downhill from there.
So I found another solution: To set the content view of my SplashActivity to an XML where I set a layout and an Image. It works perfectly for portrait and landscape in preview mode. However, when I run the app, the splash screen is nowhere to be found and it only shows a blank screen.
This is my Splash Activity.
Its XML file is:
Strangely enough, when I put the SetContentView in my MainActivity it shows in there (Even though not correctly sized) so I don't think the problem is in the XML file. I really don't know what else I could try to solve this
Hi, I just came xamarin crash I want to make a game project that should be called from unity, how can I do it, help guide me
Just starting a new Xamarin Forms 4 app and I have a question about the new routing navigation. I see two approaches to passing data now
1. You use the new routing navigation and pass your data as part of the query string.
2. You create a viewmodel, pass it to the pages constructor and then navigate to it.
I can see if you were coming from a web background that the former would be easy for you to get to grips with. It is essentiually an MVC site in an app. However I see a lot of difficulties with it. Firstly, everything gets turned into a string (and it doesn't even do the encoding for you) and I guess that means you can't pass arrays of objects and useful stuff like that. So what is the point of it, except for really simple apps? Is the new way anti ViewModel? Should I adopt the new methodology or stick with the existing way? Can I mix and match?
I mean I like having the shell stuff that explains the layout of the app and if you are deeplinking your app to web content then the new way is great. It was quite fiddly the old way.
I have tried sharpcif for file access without much luck. I was hoping someone could suggest a way to access a windows 10 share folder from an xamarin forms app?
I am developing an app for Droid, iOS and UWP. Environment: Win 10 Pro 1909; VS 2019 Pro 16.4.5; Xamarin 16.4
Recently I noticed that there are cases where only in UWP an Entry does not display data from the Model. The data is there. If I click or tap on the field the data that I expect to see there appears. That is not the expected behavior.
Thankfully I have a page that had both working fields and broken ones. The following works:
<StackLayout Orientation="Horizontal"> <Entry x:Name="Desc" FontSize="20" TextColor="Black" BackgroundColor="White" HeightRequest="48" HorizontalOptions="FillAndExpand" Text="{Binding CDM.CD.descp}" Placeholder="Description" VerticalOptions="Center" TextChanged="OnDescTextChanged" /> </StackLayout>
However, if I replace Orientation="Horizontal" with Vertical or remove the StackLayout completely, it breaks as described.
With only adding a bit of stink to the code, I can make that display as expected.
Related to this, is using an Entry within a Grid. The following code displays a blank until I tap in the field:
<Entry Grid.Row="2" Grid.Column="1" BackgroundColor="White" FontSize="18" VerticalOptions="Center" Text="Sam"/>
The Label cells display fine. The Entry cells do not (only in UWP). I suppose I could replace the Grid with a number of StackLayouts but I understand that one should not do that.
Have others come across this? any suggestions?
Thanks!
Hi everyone,
I have faced with the new issue, how to get ContentPage from MarkupExtension ?
I have tried the following method:
static class ViewExtensions { /// <summary> /// Gets the page to which an element belongs /// </summary> /// <returns>The page.</returns> /// <param name="element">Element.</param> public static Page GetParentPage(this Element element) { if (element != null) { var parent = element.Parent; while (parent != null) { if (parent is Page) { return parent as Page; } parent = parent.Parent; } } return null; } }
... but it did not work properly, parent is always null ... (
Then I have found the following question on StackOverflow https://stackoverflow.com/questions/55869794/access-contentpage-from-imarkupextension
But the solution that was suggested by Sharada Gururaj is not possible because it is internal API:
public object ProvideValue(IServiceProvider serviceProvider) { if (serviceProvider == null) throw new ArgumentNullException(nameof(serviceProvider)); if (!(serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideParentValues valueProvider)) throw new ArgumentException(); foreach (var p in valueProvider.ParentObjects) { if (!(target is ContentPage page)) continue; /// Do your processing for content-page here.. } }
I cannot find proper solution for getting ContentPage or ContentView !?
Has anyone found solution ?
I realized that in Android, if I have nested TabbedPages (one up and bottom), it looks great. But the same setup in iOS makes them end up both in the bottom and on top of each other. I am now looking for an alternative to TabbedPage on the top that would work on iOS, I checked how two major app vendors solved that type of issue and they did a switch/toggle in the page. Can anyone guide me on how to create a similar toggle in my page? See attached screenshots. Would also be interesting to know how to include such button in the top.
On the same topic I wonder how I can disable so my app content dont appear under the iOS title bar?
Hi everyone, I am trying to add ironsource framework to my xamarin.ios project.
I have added dll and framework as per the documentation(https://developers.ironsrc.com/ironsource-mobile/xamarin/get-started-ironsource-xamarin-plugin-ios/). While building the project it says
'Native References/IronSource.framework/IronSource' is not a valid framework. Stock.iOS
I have searched how to add framework to ios project and I have added --mono:framework to my additional mtouch argument (according to Microsoft docs https://docs.microsoft.com/en-us/xamarin/cross-platform/macios/native-references )
This is the output
3> /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch @/Users/alim/Library/Caches/Xamarin/mtbs/builds/Stock.iOS/35ae000f376de9e87dbe72b91cd5610c/obj/iPhoneSimulator/Debug/response-file.rsp --mono:framework "--gcc_flags=-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/alim/Library/Caches/Xamarin/mtbs/builds/Stock.iOS/35ae000f376de9e87dbe72b91cd5610c/obj/iPhoneSimulator/Debug/Entitlements.xcent"
3>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(845,3): warning : warning: ignoring file Native References/IronSource.framework/IronSource, building for iOS Simulator-i386 but attempting to link with file built for unknown-unsupported file format ( 0x56 0x65 0x72 0x73 0x69 0x6F 0x6E 0x73 0x2F 0x43 0x75 0x72 0x72 0x65 0x6E 0x74 )
3>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(845,3): warning : warning: ignoring file Native References/IronSource.framework/IronSource, building for iOS Simulator-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x56 0x65 0x72 0x73 0x69 0x6F 0x6E 0x73 0x2F 0x43 0x75 0x72 0x72 0x65 0x6E 0x74 )
3>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(845,3): error MT0140: File 'Native References/IronSource.framework/IronSource' is not a valid framework.
Hi. The following are the steps that I have taken to upgrade an app to Xamarin Forms 4.5+ and AndroidX.
It looks OK until near the end where I get errors but I do not know why. I did not get them before. Are they due to AndroidX or something else.
I have:
1) installed VS 2019 16.5.1
2) installed XF 4.5.0.495
3) in Tools->Options->Xamarin->Android Settings, I have checked Enable AndroidX Migrator (Experimental)
3) right click on the android project and select Migrate to AndroidX
That is all looking good. Now try:
4) run in debug in droid on a real phone.
get the following message:
Severity Code Description Project File Line Suppression State Error Could not find 3 Android X assemblies, make sure to install the following NuGet packages: - Xamarin.AndroidX.MediaRouter You can also copy-and-paste the following snippet into your .csproj file: <PackageReference Include="Xamarin.AndroidX.MediaRouter" Version="1.1.0" />
Hmmm... my droid.csproj file does not have lines with PackageReference on them. So, I will try to install the nuget.
The nuget installed fine. When I checked the droid.csproj file, it had the following new lines:
<Reference Include="Xamarin.AndroidX.MediaRouter, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\..\packages\Xamarin.AndroidX.MediaRouter.1.0.0\lib\monoandroid90\Xamarin.AndroidX.MediaRouter.dll</HintPath> </Reference>
So maybe those replace the PackageReference lines.
Try running again.
Now I get the message:
Severity Code Description Project File Line Suppression State Error Could not find 1 Android X assemblies, make sure to install the following NuGet packages: - Xamarin.AndroidX.AppCompat.Resources You can also copy-and-paste the following snippet into your .csproj file: <PackageReference Include="Xamarin.AndroidX.AppCompat.Resources" Version="1.1.0" /> i_TraxMobile.Droid
Ok. Try installing the nuget.
But wait! it is installed already - according to the nuget installer.
Looking in the .csproj, it is not there.
I do find
<Reference Include="Xamarin.AndroidX.AppCompat,...
and so I make a copy of the three lines and make it look like it belongs to Xamarin.AndroidX.AppCompat.Resources.
<Reference Include="Xamarin.AndroidX.AppCompat.Resources, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\..\packages\Xamarin.AndroidX.AppCompat.Resources.1.1.0\lib\monoandroid90\Xamarin.AndroidX.AppCompat.Resources.dll</HintPath> </Reference>
Close VS.
Reopen the solution in VS.
Run it.
Get a bunch of errors.
Severity Code Description Project File Line Suppression State Error resource style/Theme.AppCompat.Light.NoActionBar (aka com.itraxonline.itraxmobile:style/Theme.AppCompat.Light.NoActionBar) not found. i_TraxMobile.Droid Error resource style/Theme.AppCompat.Light.Dialog (aka com.itraxonline.itraxmobile:style/Theme.AppCompat.Light.Dialog) not found. i_TraxMobile.Droid Error failed linking references. i_TraxMobile.Droid Error resource style/Theme.AppCompat.Light.DarkActionBar (aka com.itraxonline.itraxmobile:style/Theme.AppCompat.Light.DarkActionBar) not found. i_TraxMobile.Droid Error resource style/Theme.AppCompat.Light.NoActionBar (aka com.itraxonline.itraxmobile:style/Theme.AppCompat.Light.NoActionBar) not found. i_TraxMobile.Droid Error style attribute 'attr/windowNoTitle (aka com.itraxonline.itraxmobile:attr/windowNoTitle)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 2 Error style attribute 'attr/colorPrimaryDark (aka com.itraxonline.itraxmobile:attr/colorPrimaryDark)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 2 Error style attribute 'attr/windowActionBar (aka com.itraxonline.itraxmobile:attr/windowActionBar)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 2 Error style attribute 'attr/colorPrimary (aka com.itraxonline.itraxmobile:attr/colorPrimary)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 2 Error style attribute 'attr/colorAccent (aka com.itraxonline.itraxmobile:attr/colorAccent)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 3 Error style attribute 'attr/colorAccent (aka com.itraxonline.itraxmobile:attr/colorAccent)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 4 Error style attribute 'attr/windowActionModeOverlay (aka com.itraxonline.itraxmobile:attr/windowActionModeOverlay)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 4
Where did they come from? Ok - so they came from styles.xml. But why??
Here is the styles.xml file.
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="MainTheme" parent="MainTheme.Base"> </style> <!-- Base theme applied no matter what API --> <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> <!--If you are using revision 22.1 please use just windowNoTitle. Without android:--> <item name="windowNoTitle">true</item> <!--We will be using the toolbar so no need to show ActionBar--> <item name="windowActionBar">false</item> <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette --> <!-- colorPrimary is used for the default action bar background --> <item name="colorPrimary">#2196F3</item> <!-- colorPrimaryDark is used for the status bar --> <item name="colorPrimaryDark">#1976D2</item> <!-- colorAccent is used as the default value for colorControlActivated which is used to tint widgets --> <!--<item name="colorAccent">#FF4081</item>--> <item name="colorAccent">#00CC00</item> <!-- You can also set colorControlNormal, colorControlActivated colorControlHighlight and colorSwitchThumbNormal. --> <item name="windowActionModeOverlay">true</item> <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item> </style> <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog"> <item name="colorAccent">#FF4081</item> </style> <!-- Following added for splash screen--> <!-- from http://lukealderton.com/blog/posts/2016/august/xamarin-forms-splash-screen-on-android-and-ios.aspx --> <style name="MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> </style> <style name="MyTheme" parent="MyTheme.Base"> </style> <style name="MyTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar"> <!--<item name="android:windowBackground">@drawable/splash</item>--> <item name="android:windowBackground">@drawable/splash_screen</item> <item name="android:windowNoTitle">true</item> </style> </resources>
Any insight regarding the AndroidX migration steps or how to fix these final errors are greatly appreciated.
Recently I am getting the following error while trying to pair to my mac, would anyone know how to resolve this? There is nothing on the web related to this message that I can find.
Everything I have tried so far:
-Deleting %localappdata%\Temp\Xamarin\XMA\IDB.Local
-Deleting hosts.key from %Localappdata%l\Xamarin\MonoTouch
-connecting from a different Windows machine to the mac
Current windows version:
VS19 16.5.1
Xamarin 16.5.000.521
Current Mac version:
VSMAC 8.5 Build 3183
Xamarin ios 13.14.1.39
I have another mac that this windows machine is able to pair with successfully, has all the same components, except this mac does not have the latest Mac OS update (10.15.4 which is on the one that I cant connect to), this one is still on 10.15.3... I am holding off on updating because of this issue and being unsure if its the mac update causing the issue.
I have a Stacklayout and some buttons in it and set the orientation to Horizontal.
but it will not auto line break.
how to do it?
I am currently trying to get make a custom view where I will make a grid where each children has a view that is defined by the user, then I define a DataSource with a list of items. However, I can't figure out how to make this in a custom view; the only thing I see when looking in google is the DataTemplate usage but for ListView and CollectionView, which I am not using. Any Ideas?
Code for teh Custom View:
[DesignTimeVisible(true)] public class OptionsSliderView : ContentView { #region BindableProperty: ItemTemplate. public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(OptionsSliderView), propertyChanged: ItemTemplatePropertyChanged, defaultValue: null); public DataTemplate ItemTemplate { get { return (DataTemplate)GetValue(ItemTemplateProperty); } set { SetValue(ItemTemplateProperty, value); } } private static void ItemTemplatePropertyChanged(BindableObject bindable, object oldValue, object newValue) { var mBindable = (OptionsSliderView)bindable; var mOldValue = (DataTemplate)oldValue; var mNewValue = (DataTemplate)newValue; if (mOldValue != mNewValue) { BuildSlider(mBindable, itemTemplate: mNewValue); } } #endregion #region BindableProperty: ItemHeaderTemplate. public static readonly BindableProperty ItemHeaderTemplateProperty = BindableProperty.Create(nameof(ItemHeaderTemplate), typeof(DataTemplate), typeof(OptionsSliderView), propertyChanged: ItemHeaderTemplatePropertyChanged, defaultValue: null); public DataTemplate ItemHeaderTemplate { get { return (DataTemplate)GetValue(ItemHeaderTemplateProperty); } set { SetValue(ItemHeaderTemplateProperty, value); } } private static void ItemHeaderTemplatePropertyChanged(BindableObject bindable, object oldValue, object newValue) { var mBindable = (OptionsSliderView)bindable; var mOldValue = (DataTemplate)oldValue; var mNewValue = (DataTemplate)newValue; if (mOldValue != mNewValue) { BuildSlider(mBindable, itemHeaderTemplate: mNewValue); } } #endregion #region BindableProperty: ItemsSource. public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IEnumerable), typeof(OptionsSliderView), propertyChanged: ItemsSourcePropertyChanged, defaultValue: null); public IEnumerable ItemsSource { get { return (IEnumerable)GetValue(ItemsSourceProperty); } set { SetValue(ItemsSourceProperty, value); } } private static void ItemsSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue) { var mBindable = (OptionsSliderView)bindable; var mOldValue = (IEnumerable)oldValue; var mNewValue = (IEnumerable)newValue; if (mOldValue != mNewValue) { BuildSlider(mBindable, itemsSource: mNewValue); } } #endregion ... private static void BuildSlider( OptionsSliderView optionsSliderView, DataTemplate itemTemplate = null, DataTemplate itemHeaderTemplate = null, IEnumerable itemsSource = null, ScreenPosition screenOrigin = ScreenPosition.Right, int itemsPerRow = 0, Thickness borderSize = new Thickness()) { if (itemTemplate != null && itemTemplate != optionsSliderView.ItemTemplate) { optionsSliderView.ItemTemplate = itemTemplate; } if (itemHeaderTemplate != null && itemHeaderTemplate != optionsSliderView.ItemHeaderTemplate) { optionsSliderView.ItemHeaderTemplate = itemHeaderTemplate; } if (itemsSource != null && itemsSource != optionsSliderView.ItemsSource) { optionsSliderView.ItemsSource = itemsSource; } if (optionsSliderView.Parent != null) { if (optionsSliderView.contentGrid == null) { optionsSliderView.contentGrid = new Grid(); } var gridRef = optionsSliderView.contentGrid; gridRef.Children.Clear(); gridRef.RowDefinitions = new RowDefinitionCollection(); gridRef.ColumnDefinitions = new ColumnDefinitionCollection(); gridRef.BackgroundColor = optionsSliderView.BorderColor; gridRef.Padding = optionsSliderView.BorderSize; gridRef.ColumnSpacing = 0; gridRef.RowSpacing = 0; // How should I do the gridRef.Children.Add here?; } }
Example usage:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:views="clr-namespace:ControlComponentExcercise.CustomViews" mc:Ignorable="d" x:Class="ControlComponentExcercise.MainPage"> <RelativeLayout> <StackLayout Orientation="Vertical" BackgroundColor="Gray" Padding="20" RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"> <StackLayout Orientation="Horizontal"> <Switch PropertyChanged="Switch_PropertyChanged" IsToggled="True"/> <Label Text="Should animate" /> </StackLayout> <Button Text="Change Border colors" Clicked="Button_Clicked"></Button> <Label Text="Border Size" /> <Slider ValueChanged="Slider_ValueChanged" Maximum="10" Minimum="0" /> <Button Text="Add/Remove Header Template" Clicked="Button_Clicked"></Button> <Button Text="Alternate Screen Origin" Clicked="Button_Clicked"></Button> </StackLayout> <views:OptionsSliderView BackgroundColor="Aquamarine" BorderColor="Purple" Animate="True" ScreenOrigin="Right" BorderSize="10"> <views:OptionsSliderView.ItemsSource> <x:Array Type="{x:Type x:String}"> <x:String>Item 1</x:String> <x:String>Item 2</x:String> <x:String>Item 3</x:String> <x:String>Item 4</x:String> <x:String>Item 5</x:String> </x:Array> </views:OptionsSliderView.ItemsSource> <views:OptionsSliderView.ItemTemplate> <DataTemplate x:DataType="x:String"> <Label Text="."/> </DataTemplate> </views:OptionsSliderView.ItemTemplate> <views:OptionsSliderView.ItemHeaderTemplate> <DataTemplate x:DataType="x:String"> <Label BackgroundColor="AliceBlue" Text="."/> </DataTemplate> </views:OptionsSliderView.ItemHeaderTemplate> </views:OptionsSliderView> </RelativeLayout> </ContentPage>