Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RamBachkheti
Created March 3, 2016 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RamBachkheti/8b841951aae61b5cbf19 to your computer and use it in GitHub Desktop.
Save RamBachkheti/8b841951aae61b5cbf19 to your computer and use it in GitHub Desktop.
************styles.xml *************************
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="scrollbar_shape_style">
<item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
<item name="android:scrollbarStyle">outsideOverlay</item>
<item name="android:scrollbars">vertical</item>
<item name="android:fadeScrollbars">true</item>
<item name="android:scrollbarThumbVertical">@drawable/scrollbar_vertical_thumb</item>
<item name="android:scrollbarTrackVertical">@drawable/scrollbar_vertical_track</item>
<item name="android:scrollbarSize">12dp</item>
<item name="android:scrollbarFadeDuration">2000</item>
<item name="android:scrollbarDefaultDelayBeforeFade">1000</item>
<item name="android:layout_width" >fill_parent</item>
<item name="android:layout_height" >wrap_content</item>
<item name="android:textColor" >#ffffff</item>
<item name="android:gravity" >center</item>
<item name="android:layout_margin" >3dp</item>
<item name="android:textSize" >30dp</item>
<item name="android:textStyle" >bold</item>
<item name="android:shadowColor" >#000000</item>
<item name="android:shadowDx" >1</item>
<item name="android:shadowDy" >1</item>
<item name="android:shadowRadius" >2</item>
</style>
</resources>
***********************************************************
***********************************************************
******************** Resources/drawable/scrollbar_vertical_thumb.xml ************************************
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="0"
android:endColor="#005A87"
android:startColor="#007AB8" />
<corners android:radius="6dp" />
</shape>
****************************************************************************************************
*************************** Resources/drawable/scrollbar_vertical_track.xml *******************************
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="0"
android:endColor="#005A87"
android:startColor="#007AB8" />
<corners android:radius="6dp" />
</shape>
**************************************************************************************************************
********************* MyScrollViewRenderer.cs (use it in Android Project) ***************************************
class MyScrollViewRenderer : ScrollViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
// Get the Resources object from our context
Android.Content.Res.Resources res = this.Resources;
string recordTable = res.GetString(Resource.Style.scrollbar_style);
((Xamarin.Forms.ScrollView)e.NewElement).StyleId = recordTable;
}
}
***************************************************************************************
************************* MyScrollView.cs (In Shared Project) ************************
class MyScrollView : ScrollView
{
}
***************************************************************************************
*********************** Page.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:local="clr-namespace:App5;assembly=App5.Droid"
x:Class="App5.Page">
<!--<me:MyEntry Text="In Shared Code" />-->
<local:MyScrollView>
<ListView x:Name="listView" IsVisible="true" ItemsSource="{x:Static local:App.BorrowedBooks}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Vertical" HorizontalOptions="CenterAndExpand">
<Label Text="{Binding Name}" HorizontalOptions="Center" />
<Label Text="{Binding Author}" Font="10" HorizontalOptions="Center"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</local:MyScrollView>
</ContentPage>
****************************************************************************************
******************************Book.cs***********************************************
public class Book : INotifyPropertyChanged
{
private string _name;
public string Name
{
get { return _name; }
set
{
if (value.Equals(_name, StringComparison.Ordinal))
return;
_name = value;
OnPropertyChanged();
}
}
private string _author;
public string Author
{
get { return _author; }
set
{
if (value.Equals(_author, StringComparison.Ordinal))
return;
_author = value;
OnPropertyChanged();
}
}
private string _borrower;
public string Borrower
{
get { return _borrower; }
set
{
if (value.Equals(_borrower, StringComparison.Ordinal))
return;
_borrower = value;
OnPropertyChanged();
}
}
private DateTime _dateBorrowed;
public DateTime DateBorrowed
{
get { return _dateBorrowed; }
set
{
if (value.Equals((DateTime)_dateBorrowed))
return;
_dateBorrowed = value;
OnPropertyChanged();
}
}
private bool _returned;
public bool Returned
{
get { return _returned; }
set
{
if (value.Equals(_returned))
return;
_returned = value;
OnPropertyChanged();
}
}
private Uri _imageUri;
public Uri ImageUri
{
get { return _imageUri; }
set
{
if (value.Equals(_imageUri))
return;
_imageUri = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
************************************************************************************
*******************************App.cs *****************************
Paste this code in app class
public static List<Book> BorrowedBooks = new List<Book> {
new Book {
Name = "War and Peace",
Author = "Tolstoy",
Borrower = "Karp",
DateBorrowed = new DateTime (2014, 1, 15),
Returned = false
},
new Book {
Name = "Anatham",
Author = "Stephenson",
Borrower = "Weiss",
DateBorrowed = new DateTime (2014, 2, 1),
Returned = false
},
new Book {
Name = "Pro Windows 8",
Author = "Liberty",
Borrower = "Hurwitz",
DateBorrowed = new DateTime (2014, 5, 1),
Returned = false
},
new Book {
Name = "Far From the Tree",
Author = "Solomon",
Borrower = "Belove",
DateBorrowed = new DateTime (2014, 3, 15),
Returned = false
},
new Book {
Name = "Ulysses",
Author = "Joyce",
Borrower = "Tadros",
DateBorrowed = new DateTime (2014, 5, 15),
Returned = false
}
};
*********************************** End ***************************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment