This is a flexible TableView specialized in settings for Android / iOS.
- To set separator color.
- To set selected cell color.
- To scroll to screen top and bottom.
- To set IsVisible each section.
- To set section a footer.
- To set various options of a header and a footer.
- To use DataTemplate and DataTemplateSelector in a section.
- To reorder items by drag and drop in a section.
- To set options of all the cells as SettingsView options at once.
- To set indivisual cell options. (indivisual cell options is superior to SettingsView options.)
- To set a cell HintText.
- To use an icon cached in memory at all cells.
- To change corner radius of an icon.
- To use various defined cells.
- To use Xamarin.Forms.ViewCell and the others.
iOS:iPhone5s,iPod touch6,iOS9.3
Android:version 5.1.1 (only FormsAppcompatActivity) / API22
https://www.nuget.org/packages/AiForms.SettingsView/
Install-Package AiForms.SettingsView
You need to install this nuget package to .NETStandard project and each platform project.
AppDelegate.cs
public override bool FinishedLaunching(UIApplication app, NSDictionary options) {
global::Xamarin.Forms.Forms.Init();
AiForms.Renderers.iOS.SettingsViewInit.Init(); //need to write here
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
MainActivity.cs
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
AiForms.Renderers.Droid.SettingsViewInit.Init(); // need to write here
}
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:sv="clr-namespace:AiForms.Renderers;assembly=SettingsView"
x:Class="Sample.Views.SettingsViewPage">
<sv:SettingsView HasUnevenRows="true">
<sv:Section Title="Header1" FooterText="Footer1">
<sv:CommandCell IconSource="icon.png" IconSize="60,60" IconRadius="30"
Title="Xam Xamarin" Description="[email protected]"
Command="{Binding ToProfileCommand}" CommandParameter="{Binding Parameter}"
KeepSelectedUntilBack="true"
/>
<sv:ButtonCell Title="Toggle Section" TitleColor="{StaticResource TitleTextColor}"
TitleAlignment="Center" Command="{Binding SectionToggleCommand}" />
<sv:LabelCell Title="Label" ValueText="value" />
<sv:SwitchCell Title="Switch" On="true"
Description="This is description." />
<sv:CheckboxCell Title="Checkbox" Checked="true" />
</sv:Section>
<sv:Section Title="Header2" FooterText="Footer2" IsVisible="{Binding SctionIsVisible}">
<sv:PickerCell Title="Favorites" ItemsSource="{Binding ItemsSource}" DisplayMember="Name" MaxSelectedNumber="3"
SelectedItems="{Binding SelectedItems}" KeepSelectedUntilBack="true" PageTitle="select 3 items" />
<sv:NumberPickerCell Title="NumberPicker" Min="0" Max="99" Number="15" PickerTitle="Select number" />
<sv:TimePickerCell Title="TimePicker" Format="HH:mm" Time="15:30" PickerTitle="Select time" />
<sv:DatePickerCell Title="DatePicker" Format="yyyy/MM/dd (ddd)" Date="2017/11/11" MinimumDate="2015/1/1" MaximumDate="2018/12/15" TodayText="Today's date"/>
<sv:EntryCell Title="EntryCell" ValueText="{Binding InputText.Value}" Placeholder="Input text" Keyboard="Email" TextAlignment="End" HintText="{Binding InputError.Value}" />
</sv:Section>
</sv:SettingsView>
</ContentPage>
SettingsView properties settings may as well be witten in App.xaml. For example...
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:sv="clr-namespace:AiForms.Renderers;assembly=SettingsView"
x:Class="Sample.App">
<Application.Resources>
<ResourceDictionary>
<Color x:Key="AccentColor">#FFBF00</Color>
<Color x:Key="DisabledColor">#E6DAB9</Color>
<Color x:Key="TitleTextColor">#CC9900</Color>
<Color x:Key="PaleBackColorPrimary">#F2EFE6</Color>
<Color x:Key="PaleBackColorSecondary">#F2EDDA</Color>
<Color x:Key="DeepTextColor">#555555</Color>
<Color x:Key="NormalTextColor">#666666</Color>
<Color x:Key="PaleTextColor">#999999</Color>
<x:Double x:Key="BaseFontSize">12</x:Double>
<x:Double x:Key="BaseFontSize+">14</x:Double>
<x:Double x:Key="BaseFontSize++">17</x:Double>
<x:Double x:Key="BaseFontSize-">11</x:Double>
<Style TargetType="sv:SettingsView">
<Setter Property="SeparatorColor" Value="{StaticResource DisabledColor}" />
<Setter Property="BackgroundColor" Value="{StaticResource PaleBackColorPrimary}" />
<Setter Property="HeaderBackgroundColor" Value="{StaticResource PaleBackColorPrimary}" />
<Setter Property="CellBackgroundColor" Value="{StaticResource AppBackground}" />
<Setter Property="CellTitleColor" Value="{StaticResource DeepTextColor}" />
<Setter Property="CellValueTextColor" Value="{StaticResource NormalTextColor}" />
<Setter Property="CellTitleFontSize" Value="{StaticResource BaseFontSize++}" />
<Setter Property="CellValueTextFontSize" Value="{StaticResource BaseFontSize}" />
<Setter Property="CellDescriptionColor" Value="{StaticResource NormalTextColor}" />
<Setter Property="CellDescriptionFontSize" Value="{StaticResource BaseFontSize-}" />
<Setter Property="CellAccentColor" Value="{StaticResource AccentColor}" />
<Setter Property="SelectedColor" Value="#50FFBF00" />
<Setter Property="HeaderTextColor" Value="{StaticResource TitleTextColor}" />
<Setter Property="FooterFontSize" Value="{StaticResource BaseFontSize-}" />
<Setter Property="FooterTextColor" Value="{StaticResource PaleTextColor}" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
Whereby any SettingsView in App will become the same property setttings.
- BackgroundColor
- A color of out of region and entire region. They contains header, footer and cell (in case android).
- SeparatorColor
- Row separator color.
- SelectedColor
- Backgraound color when row is selected.
Note that cell's ripple effect is not worked on Android when the cell background color is not set.
- HeaderPadding
- HeaderTextColor
- HeaderFontSize
- HeaderTextVerticalAlign
- HeaderBackgroundColor
- HeaderHeight
- They are section header options.
- FooterTextColor
- FooterFontSize
- FooterBackgroundColor
- FooterPadding
- They are section footer options.
- RowHeight
- If HasUnevenRows is false, this value apply to each row height;
- Otherwise this value is used as minimum row height.
- HasUnevenRows
- Whether row height is fixed. Default false.(recomend true)
- CellTitleColor
- CellTitleFontSize
- CellValueTextColor
- CellValueTextFontSize
- CellDescriptionColor
- CellDescriptionFontSize
- CellBackgroundColor
- CellIconSize
- CellIconRadius
- CellAccentColor
- CellHintTextColor
- CellHintFontSize
- They are bulk cell options.
- UseDescriptionAsValue (for Android)
- Whether description field is used as value field. (like general android app)
- Default false
- ShowSectionTopBottomBorder (for Android)
- Whether a separator is shown at section top and bottom. (like general android app)
- Default true
- ScrollToTop
- ScrollToBottom
- When this property is set to true, the screen will be scrolled to first item position or last item position.
- If scrolling has complete, it will be set to false automatically.
- VisibleContentHeight
- The height of the visible content. This value allows SettingsView itself height to fit total cells height.
- ItemsSource
- ItemTemplate
- A DataTemplate for entire SettingsView can be used.
If SettingsView's total cells height is shorter than the parent view height, itself height can be fit total cells height as the following:
<sv:SettingsView x:Name="settings" HeightRequest="{Binding VisibleContentHeight,Source={x:Reference settings}}">
</sv:SettingsView>
public class SomeViewModel
{
public List<MenuSection> ItemsSource {get;set;}
public SomeViewModel()
{
ItemsSource = new List<MenuSection>{
new new MenuSection("Select number",3){
new MenuItem{Title = "3",Value=3},
new MenuItem{Title = "4",Value=4},
},
new MenuSection("Select mode",1){
new MenuItem{Title = "A",Value = 1},
new MenuItem{Title = "B",Value = 2}
}
}
}
}
public class MenuItem
{
public string Title { get; set; }
public int Value { get; set; }
}
public class MenuSection:List<MenuItem>
{
public string SectionTitle { get; set; }
public bool Selected { get;set; } // must implement INotifyPropertyChanged by some way
public MenuSection(string title,int initalSelectedValue)
{
SectionTitle = title;
}
}
<sv:SettingsView x:Name="Settings" ItemsSource="{Binding ItemsSource}">
<sv:SettingsView.ItemTemplate>
<DataTemplate>
<sv:Section Title="{Binding SectionTitle}" ItemsSource="{Binding}" sv:RadioCell.SelectedValue="{Binding Selected}">
<sv:Section.ItemTemplate>
<DataTemplate>
<sv:RadioCell Title="{Binding Title}" Value="{Binding Value}" />
</DataTemplate>
</sv:Section.ItemTemplate>
</sv:Section>
</DataTemplate>
</sv:SettingsView.ItemTemplate>
</sv:SettingsView>
- ClearCache (static)
- Clear all memory cache.
- Title
- Section header text. The same as Xamarin.Forms.TableSection.
- FooterText
- Section footer text.
- IsVisible
- Whether the section is visibled.
- HeaderHeight
- Individual section header height.
- Superior to SettingsView HeaderHight.
- ItemsSource
- Specify the source of a DataTemplate.
- ItemTemplate
- Specify a DataTemplate.
- UseDragSort
- Enable you to reorder cells in a section with drag and drop.
- If iOS version is less than or equal to iOS10, the cells can be moved when grabbing the icon drawn three lines; Otherwise can be moved when doing long tap.
public class SomeModel
{
// you should use a ObservableCollection if you use a dynamic list.
public ObservableCollection<Option> Options {get;set;}
public void SomeMethod()
{
Options = new ObservableCollection(GetServerData());
}
}
public class Option
{
public string Name {get;set;}
public string Address {get;set;}
}
<sv:Section ItemsSource="{Binding Options}">
<sv:Section.ItemTemplate>
<DataTemplate>
<sv:LabelCell Title="{Binding Name}" Value="{Binding Address}" />
</DataTemplate>
</sv:Section.ItemTemplate>
</sv:Section>
- CellBase
- LabelCell
- CommandCell
- ButtonCell
- SwitchCell
- CheckboxCell
- RadioCell
- NumberPickerCell
- TimePickerCell
- DatePickerCell
- TextPickerCell
- PickerCell
- EntryCell
- Icon
- If not specify a imagesource, icon will be hidden.
- Description
- If not specify any text, description will be hidden.
- Accessory
- Be used by a CheckboxCell and a SwitchCell; Otherwise will be hidden.
- Title
- Title text.
- TitleColor
- Title text color.
- TitleFontSize
- Title text font size.
- Description
- Description text.
- DescriptionColor
- Description text color.
- DescriptionFontSize
- Description text font size.
- HintText
- Hint text.(for some information, validation error and so on)
- HintTextColor
- Hint text color.
- HintFontSize
- Hint text font size.
- BackgroundColor
- Cell background color.
- IconSource
- Icon image source. (any ImageSource object)
- IconSize
- Icon size. (width,height)
- IconRadius
- Icon corners radius.
- IsEnabled
- Whether a cell is enabled. If set to false, the entire cell color will turn translucent and the cell won't accept any operations.
You can use SVG image if SvgImageSource is installed.
https://github.com/muak/SvgImageSource
https://www.nuget.org/packages/Xamarin.Forms.Svg/
Install-Package Xamain.Forms.Svg -pre
This is a cell showing read only text.
- ValueText
- Value text.
- ValueTextColor
- Value text color.
- ValueTextFontSize
- Value text font size.
- IgnoreUseDescriptionAsValue
- Whether ignore the setting that SettingsView property of UseDescriptionAsValue.
This is a Labelcell invoked an action.
- Command
- Invoked action.
- CommandParameter
- KeepSelectedUntilBack
- When moving next page, whether keep the cell selected until being back to the page.
The others are the same as LabelText.
This is a simple cell invoked an action like a button.
- TitleAlignment
- Button title horizontal alignment.
- Command
- CommandParameter
This cell don't use Description property.
This is a LabelCell equipped a switch.
- On
- Switch toggle on / off. On is true, Off is false.
- AccentColor
- Swich accent color. (background color and so on)
This is a LabelCell equipped a checkbox.
- Checked
- Check on / off. On is true, Off is false.
- AccentColor
- Checkbox accent color. (frame and background)
This is the cell that can be selected just one item from in a Section or a SettingsView.
- Value
- A value that can be selected.
- AccentColor
- Check mark color.
- SelectedValue
- Current selected value.
- If this property is set to a section, the item can be selected just one from the section, and if set to SettingsView itself, the item can be selected just one from entire SettingsView.
Note that this property can't be set to both entire and a section. If it is set to both, a section side is used.
<sv:SettingsView>
<sv:Section Title="Sound" sv:RadioCell.SelectedValue="{Binding SelectedItem}">
<sv:RadioCell Title="Sound1" Value="{Binding Items[0]}">
<sv:RadioCell Title="Sound2" Value="{Binding Items[1]}">
</sv:Section>
</sv:SettingsView>
<sv:SettingsView sv:RadioCell.SelectedValue="{Binding GlobalSelectedItem}">
<sv:Section Title="Effect">
<sv:RadioCell Title="Sound1" Value="{Binding Items[0]}">
<sv:RadioCell Title="Sound2" Value="{Binding Items[1]}">
</sv:Section>
<sv:Section Title="Melody">
<sv:RadioCell Title="Melody1" Value="{Binding Items[2]}">
<sv:RadioCell Title="Melody2" Value="{Binding Items[3]}">
</sv:Section>
</sv:SettingsView>
This is a LabelCell calling a number picker.
- Number
- Current number.(default two way binding)
- Min
- Minimum number.
- Max
- Maximum number.
- PickerTitle
- Picker title text.
- SelectedCommand
- A command invoked when a number is selected.
This cell can't use ValueText property.
This is a LabelCell calling a time picker.
- Time
- Current time (default two way binding)
- Format
- Time format. (for example "hh:mm")
- PickerTitle
- Picker title text.
This cell can't use ValueText property.
This is a LabelCell calling a date picker.
- Date
- Current date. (default two way binding)
- MinimumDate
- MaximumDate
- Format
- Date format. (for example "ddd MMM d yyyy")
- TodayText
- Text of the button selecting today's date. (only iOS)
- If this text is empty, the button will be hidden.
This cell can't use ValueText property.
This is a LabelCell calling a text picker.
- Items
- Picker data source implementing IList.
- This property can be set a list of built-in type. (e.g. List<string>, List<int>, List<double>)
- The result of ToString method is used as appearance text.
- SelectedItem
- Selected item is set. (two-way binding)
- SelectedCommand
- A command invoked when an item is selected.
This cell can't use ValueText property.
This is a LabelCell calling a multiple select picker. When tapped on iOS, move next page and show picker there. When tapped on Android, show the picker on a dialog.
- PageTitle
- Picker page title text.
- ItemsSource
- Picker data source implementing IEnumerable.
- This have to assing a instance and must not null.
- DisplayMember
- Class member(property) name Displayed on the picker.
- SubDisplayMember
- Class member(property) name secondary displayed on the Picker. If this property is set, the cell will be two line and the first line will display DisplayMember and the second line will display SubDisplayMember.
- SelectedItems
- IList where selected items is stored.
- This have to assing a instance and must not null.
- SelectedItemsOrderKey
- Class member(Property) name that becomes a order key when selected items is displayed as text.
- SelectedCommand
- A command invoked When finished being selected items.
- MaxSelectedNumber
- Selectable items number.
- If zero, unlimited multi select mode. Else if One, single select mode. Otherwise limited multi select mode.
- KeepSelectedUntilBack
- When moving next page or showing a dialog, whether keep the cell selected until being back to the page.
- AccentColor
- Picker checkbox color.
- UseNaturalSort
- Whether use NaturalSort as sort method. default false.
- If true, for example, if the order is normally "1,10,2,3,4", is "1,2,3,4,10".
- This option may not correctly work if not used Japanese language.
- UsePickToClose
- Whether closing the Picker automatically if the number of selected items come to MaxSelectedNumber.
- UseAutoValueText
- Normally, selected items string is automatically displayed in the ValueText. If the value of this property is specified false, the auto display will be cleared and ValueText will be available as usual.
This is a cell inputing some text.
- ValueText
- Input text. (default two way binding)
- ValueTextColor
- Input text color.
- ValueTextFontSize
- Input text font size.
- MaxLength
- Input text maximum length.
- Keyboard
- Keyboard type.
- Placeholder
- Placeholder text.
- TextAlignment
- Input text horizontal alignment.
- AccentColor
- Under line color on focus. (only android)
- IsPassword
- Whether the input text is hidden or not for password.
MIT Licensed.