Picker with custom Items [Xaml] - xamarin.forms

I am trying to figure out a way how to create a picker with custom items in XAML. I am not sure if it is possible to achieve this task only using xaml. The picker would have to contain items that consist of a label and a switch. The code below illustrates the end goal:
<Picker Title="Picker title here">
<Picker.ItemsSource>
<StackLayout Orientation="Horizontal">
<Label Text="Hello Xamarin.Forms!" />
<Switch />
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="Hello Xamarin.Forms2!" />
<Switch />
</StackLayout>
</Picker.ItemsSource>
</Picker>

It's not possible. I think you can create a Popup with a ListView, where you have a ViewCell with all controls you need

Related

Xamarin's forms Date Picker android icon a bit out of way

I am trying to place a synfcusion button that has a calendar image near a xarmain forms entry box.
But its a bit out of alignment what I have tried so far is.
<Label Text="Please select a start date below"></Label>
<StackLayout Orientation="Horizontal">
<Entry x:Name="txtDateStartEntry" WidthRequest="200" ></Entry>
<syncfusion:SfButton x:Name="btnPickStartDate" CornerRadius="10" HorizontalTextAlignment="Start" ShowIcon="True" Clicked="btnPickStartDate_Clicked" FontSize="24" BorderThickness="2" TextColor="White" BackgroundColor="White" Text="..." >
<syncfusion:SfButton.Content>
<Grid ColumnDefinitions="Auto, *, Auto" ColumnSpacing="16" Padding="16">
<Image Grid.Column="1" HorizontalOptions="End" WidthRequest="30" HeightRequest="30" Source="cal16.png" VerticalOptions="End"/>
</Grid>
</syncfusion:SfButton.Content>
</syncfusion:SfButton>
</StackLayout>
What I have eneded up with is this.
As you can see its a bit far away from the entry field and doesnt look like it belongs.
If you're using Syncfusion, you should make use of SfTextInputLayout which provides leading/trailing view functionality for the express purpose of adding descriptive iconography to an input view.
Code example assumes importing the following xmlns:
xmlns:sftl="clr-namespace:Syncfusion.XForms.TextInputLayout;assembly=Syncfusion.Core.XForms"
<sftl:SfTextInputLayout TrailingViewPosition="Inside">
<Entry x:Name="txtDateStartEntry" WidthRequest="200" />
<sftl:SfTextInputLayout.TrailingView>
<Image HeightRequest="30" Source="cal16.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="btnPickStartDate_Clicked" />
</Image.GestureRecognizers>
</Image>
<sftl:SfTextInputLayout.TrailingView>
</sftl:SfTextInputLayout>
Note: when using LeadingView or TrailingView, it's recommended to not assign a Width value as Syncfusion will calculate the width based on the height you request to maintain aspect ratio of the specified view. Therefore I have intentionally excluded HeightRequest from the Image.

Devexpress Datagrid and Xamarin.Forms component in the same View

Can i have xamarin.forms component and Devexpress DataGrid in same View. I tried but only one shows.
Example:
<Entry Keyboard="Numeric" Placeholder="Enter Here" ></Entry>
<DatePicker FontSize="Large"></DatePicker>
<Button Text="Search"></Button>
<dxg:DataGridView ItemsSource="{Binding Path=Users}" RowHeight="90">
<dxg:DataGridView.Columns>
<dxg:TextColumn FieldName="Name" Caption="Name" IsReadOnly="true">
<dxg:TextColumn.Width>
<OnIdiom x:TypeArguments="GridLength" Tablet="200" Phone="120" />
</dxg:TextColumn.Width>
</dxg:TextColumn>
</dxg:DataGridView.Columns>
</dxg:DataGridView>
</Stack>```

Xamarin Forms 4.1: ScrollView scroll is covering header view in android device 9.0

In Xamarin Forms 4.1, When scroll, scrollview content is covering/overflow the headerview and scrollview content is not shown completely.
Tried with IsClippedToBounds to true.
Created scrollviewrenderer, OnDraw() -> set clip to bound property. But didn't worked.
Example: Here is the XAML design
<Stacklayout>
<HeaderView/>
<ScrollView IsClippedToBounds="true">
<Stacklayout>
<label text="1"/>
........
........
<label text="100"/>
</Stacklayout>
</ScrollView>
</Stacklayout>
I make a custom control as the headerview in your description. And test on Xamarin.forms 4.1, works well.
MyCustomConrol:
<StackLayout Orientation="Horizontal" BackgroundColor="Aqua">
<Label x:Name="Title_label" Text="Title" TextColor="Black" FontSize="25" HorizontalOptions="StartAndExpand" Margin="8,0,4,0"/>
<Button x:Name="btnHello" Text="Hello" HorizontalOptions="EndAndExpand" Margin="4,0,8,0"/>
</StackLayout>
MainPage.xaml
<StackLayout>
<local:MyCustomControl></local:MyCustomControl>
<!--<HeaderView/>-->
<ScrollView IsClippedToBounds="true">
<StackLayout>
<Label Text="1"/>
<Label Text="2"/>
<Label Text="3"/>
……………
…………………
</StackLayout>
</ScrollView>
Result:
You could download from ScrollView/XamarinDemo folder of GitHub for reference.
https://github.com/WendyZang/Test.git
If you want your header to be always visible then rather than placinf your content in Header, it will be better to place your header content first then below that place your listview. Thus, your header remains intact and listview scrolls.

Xamarin Forms group controls without modifying layout

I've got following view:
<ContentPage.Content>
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<StackLayout VerticalOptions="CenterAndExpand" Margin="20, 0, 20, 0">
<StackLayout>
<Label Text="Login" HorizontalOptions="CenterAndExpand" />
<Entry Text="{Binding Login, Mode=OneWayToSource}"></Entry>
</StackLayout>
<StackLayout>
<Label Text="Hasło" HorizontalOptions="CenterAndExpand" />
<Entry IsPassword="True" Text="{Binding Password, Mode=TwoWay}"></Entry>
</StackLayout>
<Button Text="Zaloguj się" Command="{Binding SignInCommand}"></Button>
</StackLayout>
</StackLayout>
<BoxView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" BackgroundColor="Gray" Opacity="0.5" InputTransparent="false" IsVisible="{Binding IsBusy}" />
<ActivityIndicator IsRunning="{Binding IsBusy}" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" />
</AbsoluteLayout>
</ContentPage.Content>
I want to move BoxView and ActivityIndicator to external control to make reusable component. The problem is that to achieve this I need to "group" these controls to obtain one child element.
The question is if is there any element I can use to group my controls, but which will not affect the way how controls are displayed? Alternatevlly which element I can use and how to still have effect of overlay over whole page and loading indicator?
I was trying to use AbsoluteLayout, StackLayout etc. but I couldn't position it to persist initial effect (overlay on whole page and loading indicator in the center with opacity = 1).
You can use DependencyService and reuse it in any page.
Check this tutorial.
There is also a working sample.

Xamarin Form - ScrollView and its Content

I have created one sample application and in that I have taken one ContentPage and did its design as below
<ContentPage>
<ScrollView Orientation="Horizontal" x:Name="scroll">
<StackLayout HeightRequest="50" Orientation="Horizontal">
<Label x:Name="lbl1" Text="label1!" VerticalOptions="Center" HorizontalOptions="Center" />
<Label x:Name="lbl2" Text="label2" VerticalOptions="Center" HorizontalOptions="Center" />
<Label x:Name="lbl3" Text="label3" VerticalOptions="Center" HorizontalOptions="Center" />
<Label x:Name="lbl4" Text="label4" VerticalOptions="Center" HorizontalOptions="Center" />
</StackLayout>
</ScrollView>
</ContentPage>
It works absolute fine , but when I take ContentView instead of ContentPage , I got blank page on emulator.
Is it bug ? or I did something wrong in this.
Xamarin.Forms works by bringing Pages in and out of the view. A ContentPage is a Page, but a ContentView is NOT a Page.
If it helps, a ContentView is analagous to a UserControl in WPF.
See this forum for some other explanations on the subject.

Resources