Professional Documents
Culture Documents
Vizenotları2023
Vizenotları2023
Vizenotları2023
Ders tanıtımı, Xamarin tanıtımı, kullanım alanları, içeriği, desteklediği sürümler, geliştirici araçları,
yüklemek, proje açma, kontroller, emülatör kurulum ve tanıtım, sayfa yapıları
QuotesPage örneği
1. Örnek
MyContentPage.xaml kodu
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Ders3.Views.MyContentPage">
<ContentPage.Content>
<StackLayout>
<Label Text="İçerik Sayfası!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
MyContentPage.xaml.cs kodu
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Ders3.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyContentPage : ContentPage
{
public MyContentPage ()
{
InitializeComponent ();
}
}
}
2. Örnek
QuotesPage.xaml kodu:
QuotesPage.xaml.cs kodu:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Ders3.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class QuotesPage : ContentPage
{
private int _index = 0;
private string[] _quotes = new string[]
{
"Life is like riding a bicycle. To keep your balance, you must keep
moving.",
"You can't blame gravity for falling in love.",
"Look deep into nature, and then you will understand everything
better."
};
public QuotesPage ()
{
InitializeComponent();
currentQuote.Text = _quotes[_index];
}
void Handle_Clicked(object sender, System.EventArgs e)
{
_index++;
if (_index >= _quotes.Length)
_index = 0;
currentQuote.Text = _quotes[_index];
}
}
}
DERS 4
Sayfa yapılarına devam (Tabbed Page, Carousel Page)
Carousel page de tab sayfaları arasındaki geçiş swipe(el hareketleri ile) olmaktadır.
1. Tabbed Sayfalar 1
MyTab1.xaml
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Ders4
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyTabbedPage1 : TabbedPage
{
public MyTabbedPage1 ()
{
//InitializeComponent();
Children.Add(new MyTab1());
Children.Add(new MyTab2());
}
}
}
using Ders4.Tabbed_Sayfalar;
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace Ders4
{
class MyCarouselPage: CarouselPage
{
public MyCarouselPage()
{
Children.Add(new MyTab1());
Children.Add(new MyTab2());
}
}
namespace Ders4
{
public class MyContentPage2 : ContentPage
{
public MyContentPage2 ()
{
/*Content = new StackLayout {
Children = {
new Label { Text = "Welcome to Xamarin.Forms!"
}
}
};*/
Label lblPage = new Label();
lblPage.Text = "Ders 4 ";
lblPage.FontSize = 25;
lblPage.HorizontalOptions = LayoutOptions.Center;
lblPage.VerticalOptions = LayoutOptions.Center;
Content = lblPage;
}
}
}
HorizontalOptions Örnek
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="StackLayoutDemos.Views.AlignmentPage"
Title="Alignment demo">
<StackLayout Margin="20">
<Label Text="Start"
BackgroundColor="Gray"
HorizontalOptions="Start" />
<Label Text="Center"
BackgroundColor="Gray"
HorizontalOptions="Center" />
<Label Text="End"
BackgroundColor="Gray"
HorizontalOptions="End" />
<Label Text="Fill"
BackgroundColor="Gray"
HorizontalOptions="Fill" />
</StackLayout>
</ContentPage>
VerticalOptions Örnek
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="StackLayoutDemos.Views.ExpansionPage"
Title="Expansion demo">
<StackLayout Margin="20">
<BoxView BackgroundColor="Red"
HeightRequest="1" />
<Label Text="Start"
BackgroundColor="Gray"
VerticalOptions="StartAndExpand" />
<BoxView BackgroundColor="Red"
HeightRequest="1" />
<Label Text="Center"
BackgroundColor="Gray"
VerticalOptions="CenterAndExpand" />
<BoxView BackgroundColor="Red"
HeightRequest="1" />
<Label Text="End"
BackgroundColor="Gray"
VerticalOptions="EndAndExpand" />
<BoxView BackgroundColor="Red"
HeightRequest="1" />
<Label Text="Fill"
BackgroundColor="Gray"
VerticalOptions="FillAndExpand" />
<BoxView BackgroundColor="Red"
HeightRequest="1" />
</StackLayout>
</ContentPage>
DERS 5 ve DERS 6
Sayfa yapılarına devam (Master Detail Page) ve Tasarım yapıları (Tüm Layout yapılar – Relative
Layout, Absolute Layout, Grid, Stack Layout)
1. Örnek
MyDetail.xaml kodu:
MyMenu.xaml kodu:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Ders5.MasterSayfalar.MyMenu" BackgroundColor="White">
<ContentPage.Content>
<StackLayout>
<!--<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />-->
<StackLayout Padding="10" Spacing="5"
VerticalOptions="CenterAndExpand">
<Label Text="Eğitimler" TextColor="Black"
BackgroundColor="Blue"></Label>
<Label Text="Başarı Hikayeleri" TextColor="Black"
BackgroundColor="Blue"></Label>
<Label Text="Akademi" TextColor="Black"
BackgroundColor="Blue"></Label>
<Label Text="İlk 10" TextColor="Black"
BackgroundColor="Blue"></Label>
<Label Text="Soru-Cevap" TextColor="Black"
BackgroundColor="Blue"></Label>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
MyMenu.xaml.cs kodu:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Ders5.MasterSayfalar
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyMenu : ContentPage
{
public MyMenu ()
{
InitializeComponent ();
Title = "Xamarin";
// Icon = "menu.jpg";
}
}
}
MyMasterPage.xaml.cs kodu:
using Ders5.MasterSayfalar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Ders5
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyMasterPage : MasterDetailPage
{
public MyMasterPage()
{
//InitializeComponent();
// MasterPage.ListView.ItemSelected += ListView_ItemSelected;
Master = new MyMenu();
Detail = new MyDetail();
}
namespace Ders6.Layouts
{
public class Absolute : ContentPage
{
public Absolute ()
{
/*Content = new StackLayout {
Children = {
new Label { Text = "Welcome to
Xamarin.Forms!" }
}
};*/
AbsoluteLayout layout = new AbsoluteLayout();
BoxView blue = new BoxView();
blue.BackgroundColor = Color.Blue;
layout.Children.Add(blue);
BoxView red = new BoxView();
red.BackgroundColor = Color.Red;
layout.Children.Add(red,new Rectangle(50,50,100,150));
Content = layout;
}
}
}
4. Örnek
RelativeOrnek.cs kodu:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace Ders6.Layouts
{ public class RelativeOrnek : ContentPage
{
public RelativeOrnek()
{ RelativeLayout layout = new RelativeLayout();
BoxView blue = new BoxView();
BoxView red = new BoxView();
blue.BackgroundColor = Color.Blue;
red.BackgroundColor = Color.Red;
red.Opacity = 0.6;
layout.Children.Add(blue, Constraint.Constant(50),
Constraint.Constant(50));
layout.Children.Add(red, Constraint.RelativeToParent((parent) =>
{
return parent.X + 70;
6. Örnek
StackLayout2.xaml kodu:
7. Örnek
Grid1.xaml kodu:
RelativeLayout.HeightConstraint="{ConstraintExpression
Type=RelativeToParent,
Property=Height,
Factor=0.3}">
<Label Text="$11.95" TextColor="#33353a" FontSize="60"
FontAttributes="Bold" />
<Button Text="Add $7.99 Credit" BackgroundColor="#1695a3"
BorderRadius="15" HeightRequest="30" FontSize="10" FontAttributes="Bold"
TextColor="White" />
</StackLayout>
<StackLayout
RelativeLayout.WidthConstraint="{ConstraintExpression
Type=RelativeToParent,
Property=Width,
Factor=1}"
RelativeLayout.YConstraint="{ConstraintExpression
Type=RelativeToView,
ElementName=banner,
Property=Height,
Factor=1,
Constant=30}">
<Label Text="Why pay for credit?" HorizontalOptions="Center"
FontAttributes="Bold" FontSize="15" />
<Label HorizontalOptions="Center" HorizontalTextAlignment="Center"
FontSize="13">
Because you can reach people who aren't on
SkyApp by calling mobile and landline
numbers, or spending SMS, at low-cost rates.
</Label>
</StackLayout>
</RelativeLayout>
</ContentPage.Content>
</ContentPage>
3. Örnek
AbsoluteLayoutProfile.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"
x:Class="Ders7_2.AbsoluteLayoutProfile">
<ContentPage.Content>
<AbsoluteLayout>
<Image Source="Resources/cicek.jpg" Aspect="AspectFill"
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
AbsoluteLayout.LayoutFlags="All" />
<Label Text="Relax" TextColor="White" FontSize="30"
HorizontalOptions="Center"
AbsoluteLayout.LayoutBounds="0, 20, 1, 50"
AbsoluteLayout.LayoutFlags="WidthProportional" />
<BoxView Color="Black" Opacity="0.5"
AbsoluteLayout.LayoutBounds="0, 1, 1, 100"
AbsoluteLayout.LayoutFlags="PositionProportional, WidthProportional" />
<StackLayout Orientation="Horizontal" Padding="30, 0"
AbsoluteLayout.LayoutBounds="0, 1, 1, 100"
AbsoluteLayout.LayoutFlags="PositionProportional, WidthProportional">
<Label Text="Profile" HorizontalOptions="Center"
VerticalOptions="Center" TextColor="White" FontSize="15" />
<Label Text="Meditate" HorizontalOptions="CenterAndExpand"
VerticalOptions="Center" TextColor="White" FontSize="15" />
<Label Text="Themes" HorizontalOptions="Center"
VerticalOptions="Center" TextColor="White" FontSize="15" />
</StackLayout>
</AbsoluteLayout>
</ContentPage.Content>
</ContentPage>