Skip to content

Commit 9debae4

Browse files
committed
Added Xamarin.Forms HeaderedTextBlock control library with control. Added samples for Forms projects to show how it can be used.
1 parent 1c99c16 commit 9debae4

94 files changed

Lines changed: 9680 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<ContentView
3+
x:Class="MADE.App.Views.HeaderedTextBlock"
4+
xmlns="http://xamarin.com/schemas/2014/forms"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
6+
7+
<ContentView.Resources>
8+
<ResourceDictionary>
9+
<Style x:Key="HeaderedTextBlockTextStyle" TargetType="Label">
10+
<Setter Property="TextColor" Value="#DE000000" />
11+
<Setter Property="LineBreakMode" Value="TailTruncation" />
12+
<Setter Property="FontSize" Value="18" />
13+
</Style>
14+
15+
<Style
16+
x:Key="HeaderedTextBlockHeaderStyle"
17+
BasedOn="{StaticResource HeaderedTextBlockTextStyle}"
18+
TargetType="Label">
19+
<Setter Property="TextColor" Value="#0078D7" />
20+
</Style>
21+
</ResourceDictionary>
22+
</ContentView.Resources>
23+
24+
<ContentView.Content>
25+
<StackLayout x:Name="HeaderTextBlockContainer">
26+
<Label x:Name="HeaderContent" Style="{StaticResource HeaderedTextBlockHeaderStyle}" />
27+
<Label x:Name="TextContent" Style="{StaticResource HeaderedTextBlockTextStyle}" />
28+
</StackLayout>
29+
</ContentView.Content>
30+
</ContentView>
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="HeaderedTextBlock.xaml.cs" company="MADE Apps">
3+
// Copyright (c) MADE Apps.
4+
// </copyright>
5+
// <summary>
6+
// Defines a UI element representing read-only text with a header component.
7+
// </summary>
8+
// --------------------------------------------------------------------------------------------------------------------
9+
10+
namespace MADE.App.Views
11+
{
12+
using MADE.App.Views.Extensions;
13+
using MADE.App.Views.Layout;
14+
15+
using Xamarin.Forms;
16+
using Xamarin.Forms.Xaml;
17+
18+
/// <summary>
19+
/// Defines a UI element representing read-only text with a header component.
20+
/// </summary>
21+
[XamlCompilation(XamlCompilationOptions.Compile)]
22+
public partial class HeaderedTextBlock : IHeaderedTextBlock
23+
{
24+
/// <summary>
25+
/// Defines the bindable property for the <see cref="Header"/> value.
26+
/// </summary>
27+
public static readonly BindableProperty HeaderProperty = BindableProperty.Create(
28+
nameof(Header),
29+
typeof(string),
30+
typeof(HeaderedTextBlock),
31+
null,
32+
propertyChanged: (bindable, value, newValue) =>
33+
{
34+
var control = (HeaderedTextBlock)bindable;
35+
control.HeaderContent.Text = (string)newValue;
36+
control.UpdateVisibility();
37+
});
38+
39+
/// <summary>
40+
/// Defines the bindable property for the <see cref="HeaderStyle"/> value.
41+
/// </summary>
42+
public static readonly BindableProperty HeaderStyleProperty = BindableProperty.Create(
43+
nameof(HeaderStyle),
44+
typeof(Style),
45+
typeof(HeaderedTextBlock),
46+
default(Style),
47+
propertyChanged: (bindable, value, newValue) =>
48+
{
49+
var control = (HeaderedTextBlock)bindable;
50+
control.HeaderContent.Style = (Style)newValue;
51+
});
52+
53+
/// <summary>
54+
/// Defines the bindable property for the <see cref="Orientation"/> value.
55+
/// </summary>
56+
public static readonly BindableProperty OrientationProperty = BindableProperty.Create(
57+
nameof(Orientation),
58+
typeof(Orientation),
59+
typeof(HeaderedTextBlock),
60+
Orientation.Vertical,
61+
propertyChanged: (bindable, value, newValue) =>
62+
{
63+
var control = (HeaderedTextBlock)bindable;
64+
control.UpdateOrientation();
65+
});
66+
67+
/// <summary>
68+
/// Defines the bindable property for the <see cref="Text"/> value.
69+
/// </summary>
70+
public static readonly BindableProperty TextProperty = BindableProperty.Create(
71+
nameof(Text),
72+
typeof(string),
73+
typeof(HeaderedTextBlock),
74+
null,
75+
propertyChanged: (bindable, value, newValue) =>
76+
{
77+
var control = (HeaderedTextBlock)bindable;
78+
control.TextContent.Text = (string)newValue;
79+
control.UpdateVisibility();
80+
});
81+
82+
/// <summary>
83+
/// Defines the bindable property for the <see cref="TextStyle"/> value.
84+
/// </summary>
85+
public static readonly BindableProperty TextStyleProperty = BindableProperty.Create(
86+
nameof(TextStyle),
87+
typeof(Style),
88+
typeof(HeaderedTextBlock),
89+
default(Style),
90+
propertyChanged: (bindable, value, newValue) =>
91+
{
92+
var control = (HeaderedTextBlock)bindable;
93+
control.TextContent.Style = (Style)newValue;
94+
});
95+
96+
/// <summary>
97+
/// Defines the bindable property for the <see cref="HideIfNullOrWhiteSpace"/> value.
98+
/// </summary>
99+
public static readonly BindableProperty HideIfNullOrWhiteSpaceProperty = BindableProperty.Create(
100+
nameof(HideIfNullOrWhiteSpace),
101+
typeof(bool),
102+
typeof(HeaderedTextBlock),
103+
false,
104+
propertyChanged: (bindable, value, newValue) =>
105+
{
106+
var control = (HeaderedTextBlock)bindable;
107+
control.UpdateVisibility();
108+
});
109+
110+
/// <summary>
111+
/// Initializes a new instance of the <see cref="HeaderedTextBlock"/> class.
112+
/// </summary>
113+
public HeaderedTextBlock()
114+
{
115+
this.InitializeComponent();
116+
}
117+
118+
/// <summary>
119+
/// Gets or sets the string associated with the header.
120+
/// </summary>
121+
public string Header
122+
{
123+
get => (string)this.GetValue(HeaderProperty);
124+
set => this.SetValue(HeaderProperty, value);
125+
}
126+
127+
/// <summary>
128+
/// Gets or sets the style associated with the header content.
129+
/// </summary>
130+
public Style HeaderStyle
131+
{
132+
get => (Style)this.GetValue(HeaderStyleProperty);
133+
set => this.SetValue(HeaderStyleProperty, value);
134+
}
135+
136+
/// <summary>
137+
/// Gets or sets the string associated with the text.
138+
/// </summary>
139+
public string Text
140+
{
141+
get => (string)this.GetValue(TextProperty);
142+
set => this.SetValue(TextProperty, value);
143+
}
144+
145+
/// <summary>
146+
/// Gets or sets the style associated with the text content.
147+
/// </summary>
148+
public Style TextStyle
149+
{
150+
get => (Style)this.GetValue(TextStyleProperty);
151+
set => this.SetValue(TextStyleProperty, value);
152+
}
153+
154+
/// <summary>
155+
/// Gets or sets the orientation the header and text should layout as.
156+
/// </summary>
157+
public Orientation Orientation
158+
{
159+
get => (Orientation)this.GetValue(OrientationProperty);
160+
set => this.SetValue(OrientationProperty, value);
161+
}
162+
163+
/// <summary>
164+
/// Gets or sets a value indicating whether to hide the control if the <see cref="IHeaderedTextBlock.Text"/> is null or whitespace.
165+
/// </summary>
166+
public bool HideIfNullOrWhiteSpace
167+
{
168+
get => (bool)this.GetValue(HideIfNullOrWhiteSpaceProperty);
169+
set => this.SetValue(HideIfNullOrWhiteSpaceProperty, value);
170+
}
171+
172+
/// <summary>
173+
/// Updates the layout for the control based on the current <see cref="IHeaderedTextBlock.Orientation"/> value.
174+
/// </summary>
175+
public void UpdateOrientation()
176+
{
177+
this.HeaderTextBlockContainer.SetOrientation(this.Orientation);
178+
}
179+
180+
/// <summary>
181+
/// Updates the visibility of the control based on the values of the <see cref="IHeaderedTextBlock.Header"/> and <see cref="IHeaderedTextBlock.Text"/> properties.
182+
/// </summary>
183+
public void UpdateVisibility()
184+
{
185+
if (!this.HideIfNullOrWhiteSpace || !string.IsNullOrWhiteSpace(this.Text))
186+
{
187+
this.IsVisible = true;
188+
this.HeaderContent?.SetVisible(!string.IsNullOrWhiteSpace(this.Header));
189+
this.TextContent?.SetVisible(!string.IsNullOrWhiteSpace(this.Text));
190+
}
191+
else
192+
{
193+
this.IsVisible = false;
194+
this.HeaderContent?.SetVisible(false);
195+
this.TextContent?.SetVisible(false);
196+
}
197+
}
198+
}
199+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Xamarin.Forms" Version="3.1.0.583944" />
9+
</ItemGroup>
10+
11+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
12+
<DocumentationFile>bin\Debug\netstandard2.0\MADE.App.Views.Controls.HeaderedTextBlock.Forms.xml</DocumentationFile>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
16+
<DocumentationFile>bin\Release\netstandard2.0\MADE.App.Views.Controls.HeaderedTextBlock.Forms.xml</DocumentationFile>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<Compile Remove="api\**" />
21+
<Compile Remove="articles\**" />
22+
<Compile Remove="_site\**" />
23+
<EmbeddedResource Remove="api\**" />
24+
<EmbeddedResource Remove="articles\**" />
25+
<EmbeddedResource Remove="_site\**" />
26+
<None Remove="api\**" />
27+
<None Remove="articles\**" />
28+
<None Remove="_site\**" />
29+
</ItemGroup>
30+
31+
<PropertyGroup>
32+
<LogFile>Docfx-$(TargetFramework).log</LogFile>
33+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
34+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
35+
<Version>1.0.0.0</Version>
36+
<Authors>MADE Apps</Authors>
37+
<Company>MADE Apps</Company>
38+
<Product>MADE App Xamarin.Forms HeaderedTextBlock Control Library</Product>
39+
<Description>Making App Development Easier with a component for showing a read-only text field with a header for Xamarin.Forms projects.</Description>
40+
<Copyright>Copyright (C) MADE Apps. All rights reserved.</Copyright>
41+
<PackageLicenseUrl>https://github.com/MADE-Apps/MADE-App-Components/blob/master/LICENSE</PackageLicenseUrl>
42+
<PackageProjectUrl>https://github.com/MADE-Apps/MADE-App-Components</PackageProjectUrl>
43+
<RepositoryUrl>https://github.com/MADE-Apps/MADE-App-Components</RepositoryUrl>
44+
<RepositoryType>git</RepositoryType>
45+
<PackageIconUrl>https://pbs.twimg.com/profile_images/927154020422160385/6HSRU36P_400x400.jpg</PackageIconUrl>
46+
<PackageTags>MADE App Development HeaderedTextBlock Xamarin.Forms View Custom Controls Windows Android iOS Xamarin</PackageTags>
47+
<RootNamespace>MADE.App.Views</RootNamespace>
48+
</PropertyGroup>
49+
50+
<ItemGroup>
51+
<None Remove=".gitignore" />
52+
<None Remove="docfx.json" />
53+
<None Remove="index.md" />
54+
<None Remove="log.txt" />
55+
<None Remove="toc.yml" />
56+
<None Remove="Docfx-*.log" />
57+
</ItemGroup>
58+
59+
<ItemGroup>
60+
<ProjectReference Include="..\MADE.App.Views.Controls.HeaderedTextBlock\MADE.App.Views.Controls.HeaderedTextBlock.csproj" />
61+
<ProjectReference Include="..\MADE.App.Views.Xamarin.Forms\MADE.App.Views.Xamarin.Forms.csproj" />
62+
</ItemGroup>
63+
64+
<ItemGroup>
65+
<EmbeddedResource Update="HeaderedTextBlock.xaml">
66+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
67+
</EmbeddedResource>
68+
</ItemGroup>
69+
70+
</Project>

0 commit comments

Comments
 (0)