8000 first commit · githubxiaoa/AccordionView@60963bf · GitHub
[go: up one dir, main page]

Skip to content

Commit 60963bf

Browse files
committed
first commit
0 parents  commit 60963bf

File tree

21 files changed

+6598
-0
lines changed

21 files changed

+6598
-0
lines changed

.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Autosave files
2+
*~
3+
4+
# build
5+
[Oo]bj/
6+
[Bb]in/
7+
packages/
8+
TestResults/
9+
10+
# globs
11+
Makefile.in
12+
*.DS_Store
13+
*.sln.cache
14+
*.suo
15+
*.cache
16+
*.pidb
17+
*.userprefs
18+
*.usertasks
19+
config.log
20+
config.make
21+
config.status
22+
aclocal.m4
23+
install-sh
24+
autom4te.cache/
25+
*.user
26+
*.tar.gz
27+
tarballs/
28+
test-results/
29+
Thumbs.db
30+
31+
# Mac bundle stuff
32+
*.dmg
33+
*.app
34+
35+
# resharper
36+
*_Resharper.*
37+
*.Resharper
38+
39+
# dotCover
40+
*.dotCover

Accordion.sln

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Accordion", "Accordion\Accordion.csproj", "{16BA3E33-AB37-4091-93FF-2BAAB1370BC6}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Accordion.Droid", "Droid\Accordion.Droid.csproj", "{AAE35B05-9801-4189-83F7-FBCE41CA1F86}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{16BA3E33-AB37-4091-93FF-2BAAB1370BC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{16BA3E33-AB37-4091-93FF-2BAAB1370BC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{16BA3E33-AB37-4091-93FF-2BAAB1370BC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{16BA3E33-AB37-4091-93FF-2BAAB1370BC6}.Release|Any CPU.Build.0 = Release|Any CPU
18+
{AAE35B05-9801-4189-83F7-FBCE41CA1F86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{AAE35B05-9801-4189-83F7-FBCE41CA1F86}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{AAE35B05-9801-4189-83F7-FBCE41CA1F86}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{AAE35B05-9801-4189-83F7-FBCE41CA1F86}.Release|Any CPU.Build.0 = Release|Any CPU
22+
EndGlobalSection
23+
EndGlobal

Accordion/Accordion.cs

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
using System;
2+
using System.Linq;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.Windows.Input;
6+
using Xamarin.Forms;
7+
8+
namespace Accordion
9+
{
10+
public interface ISelectable
11+
{
12+
bool IsSelected { get; set; }
13+
}
14+
15+
public class ItemsView : ScrollView
16+
{
17+
public static readonly BindableProperty ItemsSourceProperty =
18+
BindableProperty.Create(
19+
propertyName: "ItemsSource",
20+
returnType: typeof(IList),
21+
declaringType: typeof(ItemsView),
22+
defaultBindingMode: BindingMode.TwoWay,
23+
defaultValue: default(IList),
24+
propertyChanged: ItemsView.OnItemsSourceChanged);
25+
26+
public IList ItemsSource
27+
{
28+
get { return (IList)GetValue(ItemsSourceProperty); }
29+
set { SetValue(ItemsSourceProperty, value); }
30+
}
31+
32+
public static readonly BindableProperty SelectedItemProperty =
33+
BindableProperty.Create(
34+
propertyName: "SelectedItem",
35+
returnType: typeof(object),
36+
declaringType: typeof(ItemsView),
37+
defaultBindingMode: BindingMode.TwoWay,
38+
defaultValue: default(object),
39+
propertyChanged: ItemsView.OnSelectedItemChanged);
40+
41+
public object SelectedItem
42+
{
43+
get { return (object)GetValue(SelectedItemProperty); }
44+
set { SetValue(SelectedItemProperty, value); }
45+
}
46+
47+
public static readonly BindableProperty ItemTemplateProperty =
48+
BindableProperty.Create(
49+
propertyName: "ItemTemplate",
50+
returnType: typeof(DataTemplate),
51+
declaringType: typeof(ItemsView),
52+
defaultValue: default(DataTemplate),
53+
defaultBindingMode: BindingMode.TwoWay);
54+
55+
public DataTemplate ItemTemplate
56+
{
57+
get { return (DataTemplate)GetValue(ItemTemplateProperty); }
58+
set { SetValue(ItemTemplateProperty, value); }
59+
}
60+
61+
readonly ICommand selectedCommand;
62+
readonly StackLayout stackLayout;
63+
64+
public ItemsView(DataTemplate template): base()
65+
{
66+
selectedCommand = new Command<object>(item => this.SelectedItem = item);
67+
stackLayout =
68+
new StackLayout()
69+
{
70+
Orientation = StackOrientation.Horizontal,
71+
Padding = 0,
72+
Spacing = 0,
73+
HorizontalOptions = LayoutOptions.FillAndExpand
74+
75+
};
76+
this.ItemTemplate = template;
77+
this.Content = stackLayout;
78+
}
79+
80+
void Init()
81+
{
82+
stackLayout.Children.Clear();
83+
84+
if (ItemsSource == null)
85+
return;
86+
87+
foreach (var item in ItemsSource)
88+
{
89+
var content = ItemTemplate.CreateContent();
90+
var itemView = content as View;
91+
itemView.BindingContext = item;
92+
93+
itemView.GestureRecognizers.Add(new TapGestureRecognizer
94+
{
95+
Command = selectedCommand,
96+
CommandParameter = itemView as object
97+
});
98+
99+
stackLayout.Children.Add(itemView);
100+
}
101+
}
102+
103+
static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)
104+
{
105+
((ItemsView)bindable).Init();
106+
}
107+
108+
static void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue)
109+
{
110+
var itemsView = (ItemsView)bindable;
111+
112+
if (newValue == oldValue)
113+
return;
114+
115+
var items = itemsView.ItemsSource.OfType<ISelectable>();
116+
117+
foreach (var item in items)
118+
item.IsSelected = item == newValue;
119+
}
120+
}
121+
122+
public class ItemsViewModel
123+
{
124+
public IEnumerable<Item> Items
125+
{
126+
get;
127+
set;
128+
}
129+
130+
public ItemsViewModel ()
131+
{
132+
this.Items = new List<Item> {
133+
new Item { Title = "Something" },
134+
new Item { Title = "Test" },
135+
new Item { Title = "Hello" }
136+
};
137+
}
138+
}
139+
140+
public class Item: ISelectable
141+
{
142+
public bool IsSelected
143+
{
144+
get; set;
145+
}
146+
147+
public string Title { get; set; }
148+
}
149+
150+
public class App : Application
151+
{
152+
public App()
153+
{
154+
var template =
155+
new DataTemplate(() =>
156+
{
157+
var label = new Label();
158+
var layout =
159+
new StackLayout
160+
{
161+
Children =
162+
{
163+
label
164+
}
165+
};
166+
label.SetBinding(Label.TextProperty, "Title");
167+
return (object)layout;
168+
});
169+
170+
var list = new ItemsView(template);
171+
var vm = new ItemsViewModel();
172+
list.SetBinding(ItemsView.ItemsSourceProperty, "Items");
173+
list.BindingContext = vm;
174+
175+
var content = new ContentPage
176+
{
177+
Title = "Accordion",
178+
Content = new StackLayout
179+
{
180+
VerticalOptions = LayoutOptions.Center,
181+
Children = {
182+
list
183+
}
184+
}
185+
};
186+
187+
MainPage = new NavigationPage(content);
188+
}
189+
}
190+
}

Accordion/Accordion.csproj

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{16BA3E33-AB37-4091-93FF-2BAAB1370BC6}</ProjectGuid>
7+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
8+
<UseMSBuildEngine>true</UseMSBuildEngine>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>Accordion</RootNamespace>
11+
<AssemblyName>Accordion</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<TargetFrameworkProfile>Profile259</TargetFrameworkProfile>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug</OutputPath>
20+
<DefineConstants>DEBUG;</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<Optimize>true</Optimize>
26+
<OutputPath>bin\Release</OutputPath>
27+
<ErrorReport>prompt</ErrorReport>
28+
<WarningLevel>4</WarningLevel>
29+
</PropertyGroup>
30+
<ItemGroup>
31+
<Compile Include="Accordion.cs" />
32+
<Compile Include="Properties\AssemblyInfo.cs" />
33+
</ItemGroup>
34+
<ItemGroup>
35+
<Reference Include="Xamarin.Forms.Core">
36+
<HintPath>..\packages\Xamarin.Forms.2.3.1.114\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
37+
</Reference>
38+
<Reference Include="Xamarin.Forms.Platform">
39+
<HintPath>..\packages\Xamarin.Forms.2.3.1.114\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Xamarin.Forms.Xaml">
42+
<HintPath>..\packages\Xamarin.Forms.2.3.1.114\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath>
43+
</Reference>
44+
</ItemGroup>
45+
<ItemGroup>
46+
<None Include="packages.config" />
47+
</ItemGroup>
48+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
49+
<Import Project="..\packages\Xamarin.Forms.2.3.1.114\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.3.1.114\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
50+
</Project>

Accordion/Properties/AssemblyInfo.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
// Information about this assembly is defined by the following attributes.
5+
// Change them to the values specific to your project.
6+
7+
[assembly: AssemblyTitle("Accordion")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("")]
12+
[assembly: AssemblyCopyright("kimsereylam")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
18+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
19+
20+
[assembly: AssemblyVersion("1.0.*")]
21+
22+
// The following attributes are used to specify the signing key for the assembly,
23+
// if desired. See the Mono documentation for more information about signing.
24+
25+
//[assembly: AssemblyDelaySign(false)]
26+
//[assembly: AssemblyKeyFile("")]

Accordion/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Xamarin.Forms" version="2.3.1.114" targetFramework="portable45-net45+win8+wp8+wpa81" />
4+
</packages>

0 commit comments

Comments
 (0)
0