button, label fontsize (Device.GetNamedSize)

main
syneffort 2 years ago
parent d0089c9b22
commit df76ec4c77
  1. 15
      XamarinStudy/XamarinStudy/XamarinStudy/App.xaml.cs
  2. 17
      XamarinStudy/XamarinStudy/XamarinStudy/Views/SampleElementPage1.xaml
  3. 29
      XamarinStudy/XamarinStudy/XamarinStudy/Views/SampleElementPage1.xaml.cs
  4. 39
      XamarinStudy/XamarinStudy/XamarinStudy/Views/SampleElementPage2.cs
  5. 9
      XamarinStudy/XamarinStudy/XamarinStudy/XamarinStudy.csproj

@ -15,17 +15,30 @@ namespace XamarinStudy
DependencyService.Register<MockDataStore>(); DependencyService.Register<MockDataStore>();
//MainPage = new AppShell(); //MainPage = new AppShell();
//MainPage = new SampleContentPage(); //MainPage = new SampleContentPage();
//MainPage = new NavigationPage(new SampleToolbarPage()); //MainPage = new NavigationPage(new SampleToolbarPage());
//MainPage = new SampleTabPage(); //MainPage = new SampleTabPage();
//TabbedPage tabbed = new TabbedPage(); //TabbedPage tabbed = new TabbedPage();
//tabbed.Children.Add(new SampleContentPage() { Title = "Page1" }); //tabbed.Children.Add(new SampleContentPage() { Title = "Page1" });
//tabbed.Children.Add(new SampleToolbarPage() { Title = "Page2" }); //tabbed.Children.Add(new SampleToolbarPage() { Title = "Page2" });
//MainPage = tabbed; //MainPage = tabbed;
//MainPage = new SampleCarouselPage(); //MainPage = new SampleCarouselPage();
//MainPage = new SampleFlyoutPage(); //MainPage = new SampleFlyoutPage();
//MainPage = new SampleFlyoutPage2(); //MainPage = new SampleFlyoutPage2();
MainPage = new NavigationPage(new SampleNavigationPage());
//MainPage = new NavigationPage(new SampleNavigationPage());
TabbedPage tabbed = new TabbedPage();
tabbed.Children.Add(new SampleElementPage1() { Title = "XAML" });
tabbed.Children.Add(new SampleElementPage2() { Title = "CS" });
MainPage = tabbed;
} }
protected override void OnStart() protected override void OnStart()

@ -0,0 +1,17 @@
<?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="XamarinStudy.Views.SampleElementPage1">
<ContentPage.Content>
<StackLayout>
<Button x:Name="chageBackgroundColorButton" Text="Change background color" TextColor="White" BackgroundColor="Salmon" BorderWidth="15" CornerRadius="50" Clicked="chageBackgroundColorButton_Clicked">
</Button>
<Label Text="This is Lable" TextColor="DarkSlateBlue" BackgroundColor="LightPink" FontSize="Large" FontAttributes="Bold"/>
<Label Text="This is Lable" TextColor="DarkSlateBlue" BackgroundColor="LightPink" FontSize="Large" FontAttributes="Bold" HorizontalTextAlignment="End"/>
<Label Text="This is Lable" TextColor="DarkSlateBlue" BackgroundColor="LightPink" FontSize="Large" FontAttributes="Bold" HorizontalTextAlignment="Start"/>
<Label Text="This is Lable" TextColor="DarkSlateBlue" BackgroundColor="LightPink" FontSize="Large" FontAttributes="Italic" HorizontalTextAlignment="Center"/>
<Label Text="This is 30 Lable" TextColor="Red" BackgroundColor="LightPink" FontSize="30" HorizontalTextAlignment="Center"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace XamarinStudy.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class SampleElementPage1 : ContentPage
{
public SampleElementPage1()
{
InitializeComponent();
BackgroundColor = Color.White;
}
private void chageBackgroundColorButton_Clicked(object sender, EventArgs e)
{
if (BackgroundColor == Color.White)
BackgroundColor = Color.Black;
else
BackgroundColor = Color.White;
}
}
}

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace XamarinStudy.Views
{
public class SampleElementPage2 : ContentPage
{
public SampleElementPage2()
{
BackgroundColor = Color.White;
Button changeBackgroundColorButton = new Button() { Text = "Change background color", BackgroundColor = Color.DarkViolet, FontSize = 30 };
changeBackgroundColorButton.Clicked += ChangeBackgroundColorButton_Clicked;
Label label1 = new Label() { Text = "CS Label", TextColor = Color.Red, BackgroundColor = Color.DeepSkyBlue, FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)) };
Label label2 = new Label() { Text = "CS 20 Label", TextColor = Color.Red, BackgroundColor = Color.DeepSkyBlue, FontSize = 30 };
Content = new StackLayout
{
Children =
{
changeBackgroundColorButton,
label1,
label2
}
};
}
private void ChangeBackgroundColorButton_Clicked(object sender, EventArgs e)
{
if (BackgroundColor == Color.White)
BackgroundColor = Color.DarkSlateGray;
else
BackgroundColor = Color.White;
}
}
}

@ -10,10 +10,19 @@
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" /> <PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Update="Views\SampleElementPage1.xaml.cs">
<DependentUpon>SampleElementPage1.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Update="Views\SampleContentPage.xaml"> <EmbeddedResource Update="Views\SampleContentPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator> <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Update="Views\SampleElementPage1.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\SampleFlyoutPage.xaml"> <EmbeddedResource Update="Views\SampleFlyoutPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator> <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource> </EmbeddedResource>

Loading…
Cancel
Save