good afternoon,
I want this ContenPage to last 3 seconds and then fade out.
This is the XAML code:
<Grid>
<StackLayout VerticalOptions="CenterAndExpand"
BackgroundColor="White">
<Image Source="log.png"
HeightRequest="250"
x:Name="logo"/>
<Label Text="FROM"
HorizontalOptions="Center"
TextColor="Black"
FontAttributes="Bold"/>
<Label Text="MundoD"
TextColor="Black"
HorizontalOptions="Center"/>
</StackLayout>
</Grid>
I'm using the FadeTo method to achieve this requirement, but the screen does not fade, this is the C# code
logo.Opacity = 0;
await logo.FadeTo(1, 2000);
Application.Current.MainPage = new IntroOne();
Result, The view does not fade
I would appreciate some help <3
You can remove the "logo.Opacity = 0"
and change "await logo.FadeTo(1, 2000)" to "await logo.FadeTo(0, 2000)" as Jason said above.
Also, you may want to override the OnAppearing() method to set the logo's Opacity. Otherwise,
the logo will not display next time you back this page.
code is like:
protected override OnAppearing()
{
base. OnAppearing();
pic.Opacity=100;
}
Related
TLDR
CollectionView broken in iOS, cant find any solution online. Weak Google fu or just not seeing the answer.
The problem
I have a CollectionView (Lets call it A) that contains items that are only strings values for filtering on a different CollectionView (Lets call it B) containing results from selecting a filter option in CollectionView A.
I have 3 different filtering options: "All", "Close to you", "Online" in CollectionView A.
The problem is that on iOS when I select for example filter option "All" in CollectionView A for the first time on the page it does the filtering and shows the results in CollectionView B, when I choose for example filtering option "Online" in CollectionView A it filters and shows the results in CollectionView B.
But when I choose filtering option "All" for the second time in CollectionView A its not responding, no event triggers, no commands runs and its not disabled. It is only showing, but I cant do anything with it.
Expected result
Can reselect the previous item on iOS, in Android no problem.
Actual result
Cant reselect previous item on iOS, need to back to previous page in stack and then navigate back to page to reset filtering.
The xaml markup
This is the xaml markup for the CollectionView A as explained above, the only holding string values to filter on.
<CollectionView ItemsSource="{Binding FilterLocations}"
Grid.Row="2"
SelectedItem="{Binding SelectedFilterLocation}"
SelectionMode="Single"
HeightRequest="50">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal"
ItemSpacing="10" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<StackLayout xct:TouchEffect.NativeAnimation="True">
<Frame BorderColor="{StaticResource BorderColor}"
x:Name="subCategoryFrame"
Padding="14, 10">
<Label Text="{Binding .}"
x:Name="subCategoryName"
FontFamily="{StaticResource FontPoppinsLight}"
TextColor="{StaticResource PrimaryAlt}" />
</Frame>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
<CollectionView.Header>
<BoxView WidthRequest="0"
HeightRequest="1"
BackgroundColor="Transparent" />
</CollectionView.Header>
<CollectionView.Footer>
<BoxView WidthRequest="{StaticResource NormalSpacingDouble}"
HeightRequest="1"
BackgroundColor="Transparent" />
</CollectionView.Footer>
</CollectionView>
The CollectionView A is in SelectionMode:Single, and the SelectedItem is bound to a ICommand on its bound ViewModel. And in the ViewModel the selection of a item in CollectionView A will trigger a filtering in CollectionView B
What I done so far
I set up so if a item in the CollectionView A is disabled it become Red, but it dont become Red.
I have tried to add a event in the Code behind, to try and set SelectedItem to null, but that back fired and just made all events go twice, one for selecting the item on the screen and second for altering the SelectedItem in the code behind.
Code:
private void CollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (Device.RuntimePlatform == Device.iOS)
{
var collectionView = sender as CollectionView;
if (collectionView == null) return;
if (collectionView.SelectedItem != null)
{
collectionView.SelectedItem = null;
}
}
}
(I know it is a big no no to do logic stuff in the Code Behind that is not design logic, but I need to get this solved or have a quick and dirty fix because of time pressure.)
Sorry for the wall of text
Use a TapGestureRecognizer.
Below, MyItemCommand is defined in MyViewModel and {Binding .} refers to the item selected in ItemsSource.
<DataTemplate ...>
<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type vm:MyViewModel}},
Path=MyItemCommand}"
CommandParameter="{Binding .}"/>
</StackLayout.GestureRecognizers>
...
First Bind the collection view into the event selectionchange.
<CollectionView ItemsSource="{Binding FilterLocations}"
Grid.Row="2"
SelectedItem="{Binding SelectedFilterLocation}"
SelectionMode="Single"
HeightRequest="50"
SelectionChanged="collection_SelectionChanged">
then inside the event put selected item to null.
private async void collection_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
var Sender = sender as CollectionView;
if (Sender.SelectedItem == null)
return;
Sender.SelectedItem = null;
}
catch (Exception ex)
{
}
}
I want to reload items into my flowlistview when it reached its bottom. therfore, I would need a function that fires once the end is reached.
I have this flowlistview set up:
<flv:FlowListView
Grid.Column="1"
FlowItemAppearing="listview_allAds_FlowItemAppearing"
FlowColumnCount="2"
IsPullToRefreshEnabled="True"
Refreshing="listview_allAds_Refreshing"
Margin="0,10,0,0"
VerticalScrollBarVisibility="Never"
FlowItemTapped="listview_allAds_FlowItemTapped"
HasUnevenRows="True"
x:Name="listview_allAds" >
<flv:FlowListView.FlowColumnTemplate>
<DataTemplate>
<ContentView Padding="4,3,3,4"> <!--only way to set padding-->
<Frame BorderColor="#ffffff"
HasShadow="True"
Padding="0"
CornerRadius="{OnPlatform Android=5, iOS=5}">
<Grid ...>
</Frame>
</ContentView>
</DataTemplate>
</flv:FlowListView.FlowColumnTemplate>
</flv:FlowListView>
I red that there is a lot you can do with "commands" but I am not sure how to do this.
Can you help me out here?
Thanks!
You could use the FlowItemAppearing. The event you set in your code works well.
async void listview_allAds_ItemAppearing(object sender, ItemVisibilityEventArgs e)
{
if (e.ItemIndex == infos.Count/2)//2 is the FlowColumnCount of your FlowListView
{
await DisplayAlert("Alert", "Scrolled to the bottom", "OK");
}
}
Im trying for couple of days to create a page that will be having two parts:
A header
List
Header would be strechable, so when user scrolls on a list, first header goes to height of 90dp's, then scrolling of the list starts, and when user scrolls up the list, when reaches top of the list, header will be streched to maximum of 268dp's
Here is the example video of my idea:
example video
So, I have a following problem:
I need to have only one element in a header, now I have two elements (yellow and red stacks).
Here is the xaml file:
<AbsoluteLayout>
<ScrollView x:Name="RootScrollView"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1"
Scrolled="OnRootScrollViewScrolled">
<AbsoluteLayout>
<StackLayout
x:Name="EmptyLayout"
BackgroundColor="Yellow"
AbsoluteLayout.LayoutFlags="WidthProportional"
AbsoluteLayout.LayoutBounds="0,0,1,178"
Spacing="0"
InputTransparent="True">
</StackLayout>
<xforms:SfListView
AbsoluteLayout.LayoutFlags="WidthProportional"
AbsoluteLayout.LayoutBounds="0,268,1,-1"
x:Name="_listView"
ItemSize="89"
BackgroundColor="{StaticResource GrayBackgroundForList}"
ItemsSource="{Binding StockDetails}">
<xforms:SfListView.ItemTemplate>
<DataTemplate>
<cellviews:BalanceFramesCellView/>
</DataTemplate>
</xforms:SfListView.ItemTemplate>
</xforms:SfListView>
<!-- Sticky Header-->
<Frame
BackgroundColor="Red"
x:Name="TabsLayout"
Padding="0"
CornerRadius="0"
HasShadow="True"
AbsoluteLayout.LayoutFlags="WidthProportional"
AbsoluteLayout.LayoutBounds="0,178,1,90">
</Frame>
</AbsoluteLayout>
</ScrollView>
</AbsoluteLayout>
</ContentPage.Content>
CodeBehind:
private void OnRootScrollViewScrolled(object sender, ScrolledEventArgs e)
{
var position = EmptyLayout.Height + Max(0, RootScrollView.ScrollY - EmptyLayout.Height);
AbsoluteLayout.SetLayoutBounds(TabsLayout, new Rectangle(0, position, 1, TabsLayout.Height));
}
Hi I am new to Xamarin Forms and am from native iOS development.
For showing alerts / action sheets I am using this https://github.com/aritchie/userdialogs.
For implementing this I followed this How to use Acr.UserDialogs.
I am getting alert successfully by following this, but now I need to customise the OK / Cancel Button's background color, alignment, frame values, hide and show the buttons..
Thanks in advance.
I need to customise the OK / Cancel Button's background color, alignment, frame values, hide and show the buttons.
As the author said, you could do this by creating a style and apply it in AlertConfig.
For example:
In the style.xml:
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<!-- Used for the buttons -->
<item name="colorAccent">#AAAAAA</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">#FFFFFF</item>
<!-- Used for the background -->
<item name="android:background">#DDDDDD</item>
<!-- Used for the Alignment -->
<item name="android:gravity">center_horizontal</item>
</style>
And you could find this style Id in the Resource.Designer.cs.
// aapt resource value: 0x7f0b0189
public const int AlertDialogCustom = 2131427721;
Then in the code create a AlertConfig to config the alertdialog:
AlertConfig alertConfig = new AlertConfig();
alertConfig.OkText = "OKOK";
alertConfig.Message = "Message";
alertConfig.Title = "Title";
alertConfig.AndroidStyleId=2131427721;
UserDialogs.Instance.Alert(alertConfig);
With Rg.Plugins.Popup Nuget you can customize the popup.
Finally I am not using any nugget packages. Now I created my own CustomAlert class. I hope it will helpful for any one.
#Miguel Angel please look at below code
In my CustomAlert.xaml file
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="wwww/2009/xaml" x:Class="MY.UserControls.CustomAlert">
<Grid RowSpacing="0" ColumnSpacing="0">
<Grid BackgroundColor="#656565" Opacity="0.5">
</Grid>
<StackLayout BackgroundColor="{StaticResource WhiteColor}" VerticalOptions="Center" Margin="10" Padding="10" >
<Label Text="Title" FontSize="18" HorizontalTextAlignment="Center" Margin="0,0,0,0" TextColor="Black"></Label>
<Label Text="Descrption." FontSize="14"
HorizontalTextAlignment="Start"
Margin="10,10,5,5"
VerticalOptions="Center" TextColor="Gray"></Label>
<Button Text="OK" TextColor="{StaticResource WhiteColor}"
Command="{Binding DismissCustomAlertCommand}"
HorizontalOptions="Center" VerticalOptions="Center"
BackgroundColor="Red" Margin="30,0,30,0" WidthRequest="400" HeightRequest="40"></Button>
</StackLayout>
</Grid>
</ContentView>
Thank you
I would like to switch many pages between in single xaml page on click on segment control.
I want make a page like upper part of page is with segment control and below this control having simple layout that is using for replace or switch a other pages in same that below position change but upper part is still remains for next page switching.
So, i would like to code for switching page with using segment control in xaml in xamarin.forms.
There is a nuget package FreshEssentials. It has cross-platform implementation of segmented control button. Find this Github repository to understand the implementation.
Hope this help !
Refer bellow link to implement custom segment control using XAML code and Cs Code
https://github.com/sam-ss/Custom-Segmented-Control-Xamarin-Forms
Hope This Help you!
you can install from nuget this library "Plugin.Segmented.Control"
from this tutorial https://www.c-sharpcorner.com/article/segment-control-in-xamarin-forms/
and your xaml:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:control="clr-namespace:Plugin.Segmented.Control;assembly=Plugin.Segmented" xmlns:iOSForms="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" iOSForms:Page.UseSafeArea="true" xmlns:local="clr-namespace:XFSegmentControlDemo" x:Class="XFSegmentControlDemo.Views.HomePage">
<StackLayout VerticalOptions="FillAndExpand" Padding="30" Spacing="20">
<Label Text="Segmented Control" FontSize="30" TextColor="White" HorizontalOptions="CenterAndExpand" />
<control:SegmentedControl x:Name="SegmentedControl" SelectedSegment="{Binding SegmentSelection}" TintColor="White" SelectedTextColor="BlueViolet" DisabledColor="Gray" Margin="8,8,8,8">
<control:SegmentedControl.Children>
<control:SegmentedControlOption Text="Item 1" />
<control:SegmentedControlOption Text="Item 2" />
</control:SegmentedControl.Children>
</control:SegmentedControl>
<Label Text="{Binding SelectedSegment}" FontSize="40" TextColor="White" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
put this code in your viewModel
int _selectedSegement;
public int SelectedSegment {
get {
return _selectedSegement;
}
set {
_selectedSegement = value;
switch (SelectedSegment) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
OnPropertyChanged("SelectedSegment");
}
}
and the last step put this in your appDelegate
global::Xamarin.Forms.Forms.Init();
SegementedControlRenderer.Initialize();
LoadApplication(new App());