My list view has just 1 or 2 datas , but still it shows empty rows till the end of the page . This just happens in ios ., in android its working fine .
pls do tell me what changes to make to hide the empty rows
How to hide the empty rows of a list view in xamrin.forms in ios
How can I make my navigation bar text bold?
Dear experts,
I have a Master-Detail architecture, and I need to make the detail page's title text of the navigation bar bold. How can I do that the simplest way?
Here is some of my code:
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MainMDPageMenuItem;
if (item == null)
return;
item.ItemBorderColor = Color.Red; // Make a red frame around the selected item
if (PreviouslySelectedItem != null)
{
PreviouslySelectedItem.ItemBorderColor = Color.FromHex("#00a8d5"); // Return the original color to the previously selected (now deselected) item
}
var page = (Page)Activator.CreateInstance(item.TargetType);
page.Title = item.Title; // THIS IS THE TITLE I AM TALKING ABOUT
Detail = new NavigationPage(page);
IsPresented = false;
MasterPage.ListView.SelectedItem = null;
PreviouslySelectedItem = item;
}
Thanks.
How to set a control's background to current themes BackgroundColor setting?
As the Frame doesn't have BorderThickness property, I was trying to simulate it. But I want to set the BackgroundColor of the views inside the Frame to current Theme's BackgroundColor setting. How to do it?
My XAML is:
<Frame BackgroundColor="Red" Padding="3">
<StackLayout BackgroundColor="{StaticResource ???}">
... ... other views here ... ...
</StackLayout>
</Frame>
What StaticResouce value shall I use for the StackLayout.BackgroundColor?
How to add columns in Xamarin.Froms.Listview dynamically?
I had created listview in xaml and able to add columns programmatically. But when I had loaded another list with different number of columns, the UI view is not updating with the new values. Is there a way that I can update number of columns in xaml itself?
Behaviors in ControlTemplates
I have a ControlTemplate defined in App.xaml for pages with ListViews like so:
<ControlTemplate x:Key="BaseModelListPageTemplate">
<StackLayout>
<Label
Text="{TemplateBinding BindingContext.Category}"
BackgroundColor="Green"
TextColor="White"
FontSize="24"
FontAttributes="Bold"/>
<ListView
x:Name="ItemListView"
HasUnevenRows="true"
ItemsSource="{TemplateBinding BindingContext.ItemsList}"
IsPullToRefreshEnabled="true"
IsRefreshing="{TemplateBinding BindingContext.IsBusy, Mode=OneWay}"
RefreshCommand="{TemplateBinding BindingContext.ReloadCommand}"
ItemTemplate="{StaticResource BaseModelDataTemplateSelector}">
<ListView.Behaviors>
<Behaviors:ListViewScrollBehavior Command="{TemplateBinding BindingContext.LoadMoreCommand}"/>
</ListView.Behaviors>
</ListView>
</StackLayout>
</ControlTemplate>
All bindings compile with no errors. The trouble is that an InvalidOperationException gets thrown: Operation is not valid due to the current state of the object. It worked fine when it was directly in a page and not in a ControlTemplate.
StackTrace is of little help:
at Xamarin.Forms.TemplateBinding+<Apply>d__17.MoveNext () [0x00018] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\TemplateBinding.cs:82
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
at UIKit.UIKitSynchronizationContext+<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIKitSynchronizationContext.cs:24
at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/Foundation/NSAction.cs:163
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at EZDelivery.iOS.Application.Main (System.String[] args) [0x00008] in /Users/taylorartunian/Projects/EZDelivery/iOS/Main.cs:17
Using ACR.UserDialogs, can you close a dialog (like Login) in code?
I want to close the dialog if it is open when the app closes so that when the app is opened again it won't still be up. Is it possible to call close / cancel on the dialog?
Style.Triggers TargetType="Button" Property="IsEnabled"
Hello,
I wanted to give a new try to Triggers to avoid using converters / VisualState / CustomRenderer.
I got a ListView filled with data which contains several buttons. Those buttons have their IsEnabled property binded and they use a style which use a Trigger to change the TextColor / Opacity / BackgroundColor to show to user that a button is either available or not.
It doesn't seems to work as I expect.
Here is the style :
<Style x:Key="ContextualCellButtonStyle" TargetType="Button">
<Style.Triggers>
<Trigger TargetType="Button" Property="IsEnabled" Value="False">
<Setter Property="Text" Value="IsEnabled=False" />
<Setter Property="TextColor" Value="Green" />
<Setter Property="BackgroundColor" Value="Red" />
</Trigger>
<Trigger TargetType="Button" Property="IsEnabled" Value="True">
<Setter Property="Text" Value="IsEnabled=True" />
<Setter Property="TextColor" Value="Red" />
<Setter Property="BackgroundColor" Value="Green" />
</Trigger>
</Style.Triggers>
</Style>
(The values used are not the final one, it's just to debug)
As you can see, when a button is enabled, the text should be IsEnabled=True with a green background and red foreground.
If the button is not enabled, the text should be IsEnabled=False with a red background and green foreground.
In my design time model, I've set the first item to enabled and the second one to disabled :
And in my XAML, I have this :
Here is the result I got :
You can see that when the IsEnabled=False, it uses the trigger IsEnabled=True and when the IsEnabled is set to true, I don't have the style I want too.
I guess the Triggers work when the IsEnabled property changes at runtime but I'm not sure. If it is the case, what do you recommend ? A custom control ? A custom renderer ?
I would like to avoid VisualState because I'd like to use MVVM without code behind for this stuff.
I have already written some custom renderer like this but I thought Trigger would be better in this case so I won't have to create a custom control and a custom renderer :
Any help or suggestion is welcomed.
Thanks for reading so far !
How to make a Behavior property bindable?
I have created the following Behavior that prevents the user entering a numeric value greater than 35 into an Entry field:
public class EntryMaxValueBehavior : Behavior<Entry>
{
public double MaxValue { get; set; }
protected override void OnAttachedTo(Entry bindable)
{
base.OnAttachedTo(bindable);
bindable.TextChanged += OnEntryTextChanged;
}
protected override void OnDetachingFrom(Entry bindable)
{
base.OnDetachingFrom(bindable);
bindable.TextChanged -= OnEntryTextChanged;
}
void OnEntryTextChanged(object sender, TextChangedEventArgs e)
{
var entry = (Entry)sender;
if (string.IsNullOrWhiteSpace(entry.Text)) return;
var val = double.Parse(entry.Text);
if (val > MaxValue)
{
string entryText = entry.Text;
entryText = entryText.Remove(entryText.Length - 1); // remove last char
entry.Text = entryText;
}
}
}
And the xaml looks like this:
<Entry Text="{Binding Answer}" Keyboard="Numeric" FontSize="Medium" VerticalOptions="End" HorizontalOptions="FillAndExpand"
TextChanged="EntryAnswer_OnTextChanged" Grid.Row="0" Grid.Column="1">
<Entry.Behaviors>
<behaviours:EntryMaxValueBehavior MaxValue="35" />
</Entry.Behaviors>
</Entry>
This works. However, if I try to bind the MaxValue property like this:
MaxValue="{Binding MaxVal}"
I get the following compiler error:
"No property, bindable property, or event found for 'MaxValue', or mismatching type between value and property."
Does anyone have an example of how to bind a Behavior property in this manner?
Navigation in ViewModel
Hello,
I'm new to MVVM/XAML and want to implement navigation in my App.
In the View I have:
public LoginPageX()
{
InitializeComponent();
BindingContext = new LoginViewModel(Navigation);
}
And in my ViewModel:
public class LoginViewModel
{
public Command LoginCommand { get; set; }
INavigation navigation;
public LoginViewModel(INavigation loginPageNav)
{
navigation = loginPageNav;
LoginCommand = new Command(async () => await OfflineButton());
}
public async Task OfflineButton()
{
navigation.InsertPageBefore(new MainPageX(), LoginPageX);
await navigation.PopAsync();
}
}
I'm a little confused about how to navigation.InsertPageBefore(new MainPageX(), what page?);
How to add a Label to a Relative layout and center it horizontally
Hi all,
I'm trying to horizontally center a label in a Relative Layout.
My intuitive way of doing it would be to add the label to the layout with an X constraint equal to the parent's width minus the label's width, all divided by two.
However, the parent's width can be had. The Label's width equals -1.
RelativeLayout relativeLayout = new RelativeLayout();
Label CenteredLabel = new Label ();
CenteredLabel.Text = "Center this";
CenteredLabel.XAlign = TextAlignment.Center;
CenteredLabel.MinimumWidthRequest = relativeLayout.Width;
relativeLayout.Children.Add
(CenteredLabel, Constraint.RelativeToParent ((parent)=>
{return (parent.Width-CenteredLabel.Width)/2;}),
Constraint.Constant(0)
);
Can anyone suggest why this is not working? Thanks!
Icon & text inside a button
Hello everybody,
I'm here because I have a problem to display an icon and text inside a button. All is right with the iOS part but the Android one is a bit more sneaky.
I'm using Xamarin.Forms so I don't know if I would have to post my question in the Xamarin.Android forum place.
So here is how that should looks (this is the iOS part):
And the result for the Android part:
I guess I have to add "padding" on this image inside the button but there is also too much native padding between the icon and the text.
Here is my code:
Button code in view:
navButton = new CustomButtonGradient
{
Text = Strings.MapPageNavButtonText,
TextColor = Color.White,
FontFamily = Fonts.SFUiText,
FontAttributes = FontAttributes.Bold,
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(CustomButtonGradient)),
Image = Images.FaCar,
BackgroundStartColor = Color.FromHex("D96B57"),
BackgroundEndColor = Color.FromHex("D6523A"),
BackgroundColor = Color.Red,
BorderRadius = 31,
HeightRequest = 62,
VerticalOptions = LayoutOptions.End,
Margin = new Thickness(10, 0, 10, 0)
};
My CustomControl:
public class CustomButtonGradient : Button
{
public CustomButtonGradient()
{
}
public Color BackgroundStartColor { get; set; }
public Color BackgroundEndColor { get; set; }
}
The iOS CustomRenderer:
public class CustomButtonGradientRenderer : ButtonRenderer
{
public CustomButtonGradientRenderer()
{
}
public override void LayoutSubviews()
{
foreach (var layer in Control?.Layer.Sublayers.Where(layer => layer is CAGradientLayer))
layer.Frame = Control.Bounds;
base.LayoutSubviews();
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged(e);
var button = e.NewElement as CustomButtonGradient;
if (e.OldElement == null)
{
var gradient = new CAGradientLayer();
gradient.CornerRadius = Control.Layer.CornerRadius = button.BorderRadius;
gradient.Colors = new CGColor[]
{
button.BackgroundStartColor.ToCGColor(),
button.BackgroundEndColor.ToCGColor()
};
var layer = Control?.Layer.Sublayers.FirstOrDefault();
Control?.Layer.InsertSublayerBelow(gradient, layer);
}
}
}
The Android CustomRenderer (for the moment):
public class CustomButtonGradientRenderer : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
Control.SetAllCaps(false);
Control.SetTypeface(Typeface.Default, TypefaceStyle.Normal);
Control.SetPadding(0, 0, 0, 0);
var button = e.NewElement as CustomButtonGradient;
if (e.OldElement == null) // perform initial setup
{
var gradient = new GradientDrawable(GradientDrawable.Orientation.TopBottom, new[] {
button.BackgroundStartColor.ToAndroid().ToArgb(),
button.BackgroundEndColor.ToAndroid().ToArgb()
});
gradient.SetCornerRadius((float)100.0);
Control.SetBackground(gradient);
//Control.SetBackgroundDrawable(gradient);
}
}
}
Thanks for your help.
Best Regards,
Thibault
Azure SQL and API app not working."This [app name].azurewebsites.net page can’t be found"
the problem is that when publishing API from visual studio to azure, and trying to deploy the website, google cant find the page
I have set up my MySQL and API app in azure. And when creating a new project (web api) in xamarin forms and publishing my API app, everything seems to work, untill i try to open https://[app name].azurewebsites.net/
I have followed these steps, but cant figure out what the source of the problem is:
https://azuremobilehelp.com/creating-api-azure/
https://azuremobilehelp.com/creating-sql-azure-database/
Using AbsoluteLayout for a background image but an element not correctly positioned
Hi, I am using a relative layout to add a background image so that I can set the aspect property, however now that I've done that, the share button which was supposed to be at the bottom of the screen is no longer there.
This is my code (inside the ContentPage):
<RelativeLayout Parent="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Image Source="Background.jpg" Aspect="Fill" RelativeLayout.WidthConstraint= "{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint= "{ConstraintExpression Type=RelativeToParent, Property=Height}"></Image>
<StackLayout>
<Label Text="Timetable" TextColor="Silver" HorizontalOptions="EndAndExpand" Margin="0, 10, 20, 0">
</Label>
<Image Margin="15, 20" HorizontalOptions="Center" WidthRequest="350" Source="subtle-logo.png"></Image>
<Image HorizontalOptions="Center" x:Name="PlayPauseButton" Source="play.png" WidthRequest="75">
</Image>
<Image HorizontalOptions="Center" x:Name="shareButton" Source="share-button.png" WidthRequest="50"
VerticalOptions="End" Margin="0, 0, 0, 20">
</Image>
</StackLayout>
</RelativeLayout>
This is it currently:
us.v-cdn.net/5019960/uploads/editor/ew/7on5hu6uszq0.png
This is where it should be (without the background image and without the relative layout).
us.v-cdn.net/5019960/uploads/editor/i4/r20ottjzqdhc.png
Can some one give me guidance on this message please.. I am working on the Android project
Can some one give me guidance on this message please.. I am working on the Android project and its giving me some message about apple...
Since I have now split my projects up in to apple or Android since they seem to not beable to live in the same project.. should I just remove the apple project from the Android build of the project... this is so very frustrating... Yesterday I thought I had it working.. today it back to feathers...
Iam not sure what it's trying to tell me as I am on the Android project...
Severity Code Description Project Path File Line Source Suppression State
Error The OutputPath property is not set for project 'XXXiOS.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='iPhone'. This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform. XXX.iOS Build
Listview item selected is not working for 2nd time selection
I had a listview with n list items. I had selected list item "a" and able to access data related to that item and once I come back to the list and attempted to select item "a" again which does nothing. It is working only If I select item "a" then "b" and then back to "a". Is there a way to do repetitive selection of same item in xamarin forms?
Bad location Google Maps Xamarin Forms (Middle of the ocean)
I'm using Xamarin.forms.Maps and ExtendedMap, I did make a custom control, here I can get the location when the user tap on map but by default the map position is in the middle of the occean, something like this 0.0756931, 0.0786793. I was seaching and trying for a while but I did not find the solution.
I did see that the map is loading the region.LatitudeDegrees and region.LongitudeDegrees but I really don't why is this happen,
Xamarin.Forms 3.0.0.482510
Xamarin.Forms.Maps 3.0.0.482510
Xamarin.Plugin.ExternalMaps 4.0.1
MapGoogleView.xaml
<local:ExtendedMap
WidthRequest="320" HeightRequest="200"
x:Name="MyMap" Tap="OnTap"
IsShowingUser="true"
MapType="Street"/>
MapGoogleView.xaml.cs
public MapGoogleView(double lat, double lon)
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
var map = new ExtendedMap(
MapSpan.FromCenterAndRadius(
new Position(lat, lon), Distance.FromMiles(0.3)))
{
IsShowingUser = true,
HeightRequest = 100,
WidthRequest = 900,
VerticalOptions = LayoutOptions.FillAndExpand,
MapType = MapType.Street
};
var stack = new StackLayout { Spacing = 0 };
stack.Children.Add(map);
Content = stack;
var position = new Position(lat, lon); // Latitude, Longitude
var pin = new Pin
{
Type = PinType.Generic,
Position = position,
Label = "Ubicación",
Address = "Latitud: " + lat.ToString() + ", Longitud: " + lon.ToString(),
};
MyMap.Pins.Add(pin);
map.MoveToRegion(
MapSpan.FromCenterAndRadius(
new Position(lat, lon), Distance.FromMiles(1)));
}
ExtendedMap.cs
public class ExtendedMap : Map
{
public event EventHandler<TapEventArgs> Tap;
public ExtendedMap()
{
}
public ExtendedMap(MapSpan region) : base(region)
{
}
public void OnTap(Position coordinate)
{
OnTap(new TapEventArgs { Position = coordinate });
}
public async void OnTap(Position coordinate)
{
try
{
OnTap(new TapEventArgs { Position = coordinate });
}
catch (Exception error)
{
await Application.Current.MainPage.DisplayAlert(
"Error",
error.Message,
"Aceptar");
return;
}
}
protected virtual void OnTap(TapEventArgs e)
{
var handler = Tap;
if (handler != null) handler(this, e);
}
}
public class TapEventArgs : EventArgs
{
public Position Position { get; set; }
}
}
Droid
ExtendedMapRenderer.cs
public class ExtendedMapRenderer : MapRenderer, IOnMapReadyCallback
{
private GoogleMap _map;
public void OnMapReady(GoogleMap googleMap)
{
_map = googleMap;
if (_map != null)
//_map.GestureRecognizer.Add(new);
_map.MapClick += googleMap_MapClick;
}
public ExtendedMapRenderer()
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Map> e) //cambiar a xamarin.forms.view
{
if (_map != null)
_map.MapClick -= googleMap_MapClick;
base.OnElementChanged(e);
if (Control != null)
((MapView)Control).GetMapAsync(this);
}
private void googleMap_MapClick(object sender, GoogleMap.MapClickEventArgs e)
{
((ExtendedMap)Element).OnTap(new Position(e.Point.Latitude, e.Point.Longitude));
}
}
I need the map can be centered on my position, I am get the position using Xam.Plugin.Geolocator
Thanks in advance.
Tap on map to get location Xamarin.forms.Maps
I did implement maps in Xamarin Forms following this instructions but now I need to get the location when the user tap on the map.
I did see that is necessary to create a custom control to do that, but, I can't find a good solution to reach that.
I am testing only in Android.
MapGoogle.xaml
<maps:Map WidthRequest="320" HeightRequest="200"
x:Name="MyMap"
IsShowingUser="true"
MapType="Street"/>
MapGoogle.xaml.cs
public MapGoogleView(double lat, double lon)
{
try
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
var map = new Map(
MapSpan.FromCenterAndRadius(
new Position(lat, lon), Distance.FromMiles(0.3)))
{
IsShowingUser = true,
HeightRequest = 100,
WidthRequest = 960,
VerticalOptions = LayoutOptions.FillAndExpand,
MapType = MapType.Street
};
var stack = new StackLayout { Spacing = 0 };
stack.Children.Add(map);
Content = stack;
var position = new Position(lat, lon); // Latitude, Longitude
var pin = new Pin
{
Type = PinType.Generic,
Position = position,
Label = "Ubicación",
Address = "Latitud: " + lat.ToString() + ", Longitud: " + lon.ToString(),
};
MyMap.Pins.Add(pin);
map.MoveToRegion(
MapSpan.FromCenterAndRadius(
new Position(lat, lon), Distance.FromMiles(1)));
}
Xamarin.Forms 3.0.0.482510
Xamarin.Forms.Maps 3.0.0.482510
What is the best way to get that?
Thanks in advance.
Stringformat issues with dates and times... is this a xamarin bug??
Hi all,
I asked a question on this yesterday and had to give up... but before I did I did a search of this forum and found these two links..
As stated before... I am trying to format a llistview in xamerin that has more than one column of data.. to of the values are dates..
My issue is that one column shows a date and then 00:00:00 for time.. I don't want the time in this column ... and I have another column that I want to display the date and time but I don't want it to display the letter T.
Also something that I did not type in the question yesterday is that I need the column labeled..
So reading over these to post.. it appears that xamarin can do this this at all... is this true.
My code
<Label Text="{Binding LAST_X_UPDATE, StringFormat='Date Updated = {0:MMMM d, yyyy HH:mm}'}"/>
this yields Date Updated 2018-12-12T22:12:00
Is this another xamerin bug?? Thanks again!
...
https://forums.xamarin.com/discussion/25666/using-stringformat-in-xaml-on-a-binding
https://forums.xamarin.com/discussion/18170/using-stringformat-in-binding-in-xaml
is there a Tabbed view in Xamarin.forms?
Hello,
any idea how to make a Tabbed view in xamarin.forms,
i only found Tabbed page which is not possible to put it inside a content page!
choosing Xamarin.forms is bad choice? should i've used each platforme beside with xamarin.android and xamarin.ios!
Thanks in advance
Can not add Xamarin.Essentials.
Hi
When i try to add Xamarin.Essentials package to Xamarin.Android project i am getting following error. Can any one tell me how can i resolve this error.
Error:
Severity Code Description Project File Line Suppression State
Error NU1107 Version conflict detected for Xamarin.Android.Support.Compat. Reference the package directly from the project to resolve this issue.
MyProject.Android -> MyProject -> Xamarin.Essentials 1.0.0 -> Xamarin.Android.Support.Core.Utils 26.1.0.1 -> Xamarin.Android.Support.Compat (= 26.1.0.1)
MyProject.Android -> Xamarin.Android.Support.CustomTabs 25.4.0.2 -> Xamarin.Android.Support.Compat (= 25.4.0.2).
Thanks.