Skip to content

Commit ee04c4b

Browse files
Updated Readme
1 parent 3962e0a commit ee04c4b

4 files changed

Lines changed: 347 additions & 13 deletions

File tree

README.md

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,288 @@
11
# SharedXFormCoreLibrary
22
A shared library containing recurring features & utilities for .NETStandard Xamarin.Forms applications
3+
4+
# Nuget
5+
Get the latest version from nuget.org<br>
6+
[![NuGet](https://img.shields.io/nuget/v/SharedXFormCoreLibrary.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/SharedXFormCoreLibrary/)
7+
[![NuGet](https://img.shields.io/nuget/dt/SharedXFormCoreLibrary.svg)](https://www.nuget.org/packages/SharedXFormCoreLibrary)
8+
9+
## Available content
10+
Please find a list of available content below.
11+
12+
### Behaviors
13+
14+
#### Namespace
15+
```xaml
16+
xmlns:behaviors="clr-namespace:AndreasReitberger.Shared.XForm.Core.Behaviors;assembly=SharedXFormCoreLibrary"
17+
```
18+
19+
#### EventToCommandBehavior
20+
This `Behavior` executes a `Command` when the specified `Event` is fired.
21+
22+
```xaml
23+
<sliders:SfSlider
24+
Margin="0,4"
25+
Minimum="0" Maximum="{Binding LimitFan}"
26+
StepSize="1"
27+
MinorTicksPerInterval="100"
28+
ShowLabels="True"
29+
>
30+
<sliders:SfSlider.Behaviors>
31+
<behaviors:EventToCommandBehavior
32+
EventName="ValueChangeEnd"
33+
Command="{Binding SetFanCommand}"
34+
/>
35+
</sliders:SfSlider.Behaviors>
36+
</sliders:SfSlider>
37+
```
38+
39+
### Converters
40+
41+
#### Namespace
42+
```xaml
43+
xmlns:converters="clr-namespace:AndreasReitberger.Shared.XForm.Converters;assembly=SharedXFormCoreLibrary"
44+
```
45+
46+
#### BooleanReverseVisibilityConverter & BooleanVisibilityConverter
47+
This `Converter` converts a `Boolean` into a reverse and non-reverse visibility (if `value` is `true`, it returns `false`)
48+
49+
```xaml
50+
<Label
51+
Style="{StaticResource SmallLabelStyle}"
52+
TextColor="{DynamicResource Error}"
53+
Text="{x:Static localization:Strings.NotAvailableDots}"
54+
IsVisible="{Binding HasDoubleExtruder, Converter={StaticResource BooleanReverseVisibilityConverter}}"
55+
/>
56+
```
57+
58+
#### ByteArrayToImageConverter
59+
This `Converter` converts a `byte[]` into an `Image`
60+
61+
```xaml
62+
<Image
63+
VerticalOptions="Start"
64+
Margin="{OnIdiom Phone='-4,0', Tablet='-62,0', Default='-4,0'}"
65+
Source="{Binding Thumbnail, Converter={StaticResource ByteArrayToImageConverter}}"
66+
>
67+
<Image.Style>
68+
<Style TargetType="Image">
69+
<Setter Property="Aspect" Value="AspectFit"/>
70+
<Style.Triggers>
71+
<DataTrigger
72+
TargetType="Image"
73+
Binding="{Binding IsPortrait}"
74+
Value="False">
75+
<Setter Property="Aspect" Value="AspectFill"/>
76+
</DataTrigger>
77+
</Style.Triggers>
78+
</Style>
79+
</Image.Style>
80+
</Image>
81+
```
82+
83+
#### ColorToBlackWhiteConverter
84+
This `Converter` converts a `Color` into `Colors.White` or `Colors.Black`. This helps to get the
85+
accurate `oreground` for a colored `Background`.
86+
87+
```xaml
88+
<Border
89+
BackgroundColor="{Binding HexCode, Converter={StaticResource StringToColorConverter}, Mode=OneWay}"
90+
>
91+
<Label
92+
Text="{Binding HexCode}"
93+
TextColor="{Binding Source={RelativeSource AncestorType={x:Type Border}}, Path=BackgroundColor, Converter={StaticResource ColorToBlackWhiteConverter}, Mode=OneWay}"
94+
Style="{StaticResource LabelStyle}"
95+
VerticalTextAlignment="Center"
96+
HorizontalTextAlignment="Center"
97+
/>
98+
</Border>
99+
```
100+
101+
102+
#### DoubleHoursToTimeSpanConverter
103+
This `Converter` converts a `Double` into a `TimeSpan`.
104+
105+
```xaml
106+
<Label
107+
LineBreakMode="WordWrap" Margin="2,10,0,10"
108+
VerticalTextAlignment="Center"
109+
FontSize="{OnIdiom Tablet=14, Default=12}"
110+
>
111+
<Label.Style>
112+
<Style TargetType="Label" BasedOn="{StaticResource TitleViewHeadlineLabelStyle}">
113+
<Setter Property="IsVisible" Value="False"/>
114+
<Style.Triggers>
115+
<MultiTrigger
116+
TargetType="Label">
117+
<MultiTrigger.Conditions>
118+
<BindingCondition Binding="{Binding IsPrinting, Mode=TwoWay}" Value="True"/>
119+
<BindingCondition Binding="{Binding ShowRemainingPrintTimeInTitleView}" Value="True"/>
120+
</MultiTrigger.Conditions>
121+
<Setter Property="IsVisible" Value="True"/>
122+
</MultiTrigger>
123+
</Style.Triggers>
124+
</Style>
125+
</Label.Style>
126+
<Label.FormattedText>
127+
<FormattedString>
128+
<Span Text="("/>
129+
<Span Text="{Binding RemainingPrintTime, Converter={StaticResource DoubleHoursToTimeSpanConverter}}"/>
130+
<Span Text=")"/>
131+
</FormattedString>
132+
</Label.FormattedText>
133+
</Label>
134+
```
135+
136+
137+
#### DoubleHoursToTimeSpanConverter
138+
This `Converter` converts a `List<string>` into a single `String` with the defined separator char.
139+
140+
#### LongToGigaByteConverter
141+
This `Converter` converts a `long` into a `Double`. The result wil be in GigaBytes.
142+
143+
#### LongToMegaByteConverter
144+
This `Converter` converts a `long` into a `Double`. The result wil be in MegaBytes.
145+
146+
#### StringToColorConverter
147+
This `Converter` converts a `String` (hex formated string) into a `Color`.
148+
149+
#### UnixDateToDateTimeConverter
150+
This `Converter` converts a `Double` (UNIX based) into a `DateTime`.
151+
152+
```xaml
153+
<Label
154+
LineBreakMode="WordWrap" Margin="2,10,0,10"
155+
VerticalTextAlignment="Center"
156+
FontSize="{OnIdiom Tablet=14, Default=12}"
157+
>
158+
<Label.FormattedText>
159+
<FormattedString>
160+
<Span Text="("/>
161+
<Span Text="{Binding CurrentDateTime, Converter={StaticResource UnixDateToDateTimeConverter}}"/>
162+
<Span Text=")"/>
163+
</FormattedString>
164+
</Label.FormattedText>
165+
</Label>
166+
```
167+
168+
#### UnixDoubleHoursToTimeSpanConverter
169+
This `Converter` converts a `Double` (UNIX based) into a `TimeSpan`.
170+
171+
```xaml
172+
<Label
173+
LineBreakMode="WordWrap" Margin="2,10,0,10"
174+
VerticalTextAlignment="Center"
175+
FontSize="{OnIdiom Tablet=14, Default=12}"
176+
>
177+
<Label.FormattedText>
178+
<FormattedString>
179+
<Span Text="("/>
180+
<Span Text="{Binding RemainingPrintTime, Converter={StaticResource UnixDoubleHoursToTimeSpanConverter}}"/>
181+
<Span Text=")"/>
182+
</FormattedString>
183+
</Label.FormattedText>
184+
</Label>
185+
```
186+
187+
#### UriToStringConverter
188+
This `Converter` converts a `Uri` into a `String`.
189+
190+
### Helpers
191+
192+
#### Namespace
193+
```cs
194+
namespace AndreasReitberger.Shared.XForm
195+
```
196+
197+
#### ViewModelBase
198+
This `Class` contains all needed properties for a ViewModel. You can inherit from this Class directly for your ViewModel,
199+
or create an own ViewModelBase and inherit there form this class.
200+
201+
```cs
202+
public partial class BaseViewModel : ViewModelBase
203+
{
204+
#region Properties
205+
206+
#region App
207+
bool _isBeta = SettingsStaticDefault.App_IsBeta;
208+
public new bool IsBeta
209+
{
210+
get { return _isBeta; }
211+
set { SetProperty(ref _isBeta, value); }
212+
}
213+
bool _isLightVersion = SettingsStaticDefault.App_IsLightVersion;
214+
public bool IsLightVersion
215+
{
216+
get { return _isLightVersion; }
217+
set { SetProperty(ref _isLightVersion, value); }
218+
}
219+
220+
bool _isTabletMode = false;
221+
public bool IsTabletMode
222+
{
223+
get { return _isTabletMode; }
224+
set { SetProperty(ref _isTabletMode, value); }
225+
}
226+
#endregion
227+
228+
#region Navigation
229+
bool _isViewShown = false;
230+
public bool IsViewShown
231+
{
232+
get { return _isViewShown; }
233+
set { SetProperty(ref _isViewShown, value); }
234+
}
235+
#endregion
236+
237+
#region Connection
238+
bool _isConnecting = false;
239+
public bool IsConnecting
240+
{
241+
get { return _isConnecting; }
242+
set { SetProperty(ref _isConnecting, value); }
243+
}
244+
#endregion
245+
246+
#endregion
247+
248+
#region Constructor
249+
public BaseViewModel()
250+
{
251+
252+
}
253+
#endregion
254+
255+
#region LiveCycle
256+
public void OnDisappearing()
257+
{
258+
try
259+
{
260+
if (SettingsApp.SettingsChanged)
261+
{
262+
// Notify other modules
263+
MessagingCenter.Send(new AppMessageInfo(), AppMessages.OnSettingsChanged.ToString());
264+
SettingsApp.SaveSettings();
265+
SettingsApp.SettingsChanged = false;
266+
}
267+
}
268+
catch (Exception exc)
269+
{
270+
// Log error
271+
EventManager.Instance.LogError(exc);
272+
}
273+
}
274+
#endregion
275+
}
276+
```
277+
278+
#### JsonConvertHelper
279+
This `Class` uses Newtonsoft.JSON in order to serialize and deserialize objects to strings and vice reverse.
280+
This is helpful if you want to store Collections or custom objects in the MAUI.Preferences (Settings).
281+
282+
```cs
283+
// Convert to a String
284+
SettingsApp.WebCam_DefaultWebCamSettings = JsonConvertHelper.ToSettingsString(value);
285+
286+
// Convert back to an object
287+
ObservableCollection<KlipperWebCamSettingsInfo> webcams = JsonConvertHelper.ToObject(SettingsApp.WebCam_Settings, new ObservableCollection<KlipperWebCamSettingsInfo>());
288+
```

common.props

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
<Project>
3+
<PropertyGroup>
4+
<Version>1.0.0</Version>
5+
<!--<PackageIcon>logo_128.png</PackageIcon>-->
6+
<NeutralLanguage>en</NeutralLanguage>
7+
<PackageProjectUrl>https://github.com/AndreasReitberger/SharedXFormCoreLibrary</PackageProjectUrl>
8+
<RepositoryUrl>https://github.com/AndreasReitberger/SharedXFormCoreLibrary</RepositoryUrl>
9+
<RepositoryType>git</RepositoryType>
10+
<PackageReleaseNotes>Check GitHub releases for changelog.</PackageReleaseNotes>
11+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
12+
<PackageReadmeFile>README.md</PackageReadmeFile>
13+
<Authors>Andreas Reitberger</Authors>
14+
<Copyright>Andreas Reitberger</Copyright>
15+
<Company>Andreas Reitberger</Company>
16+
<LangVersion>11</LangVersion>
17+
<PublishReadyToRun>false</PublishReadyToRun>
18+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
19+
20+
<!--Source-Linking-->
21+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
22+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
23+
<IncludeSymbols>true</IncludeSymbols>
24+
</PropertyGroup>
25+
26+
<!--
27+
<ItemGroup>
28+
<None Include="..\..\art\logo_128.png">
29+
<Pack>True</Pack>
30+
<PackagePath></PackagePath>
31+
</None>
32+
</ItemGroup>
33+
-->
34+
<ItemGroup>
35+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
36+
</ItemGroup>
37+
</Project>

src/SharedXFormCoreLibrary.sln

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.8.34219.65
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedXFormCoreLibrary", "SharedXFormCoreLibrary\SharedXFormCoreLibrary.csproj", "{8C0AECB5-07A5-4EA8-9AF0-526F0B80C414}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharedXFormCoreLibrary", "SharedXFormCoreLibrary\SharedXFormCoreLibrary.csproj", "{8C0AECB5-07A5-4EA8-9AF0-526F0B80C414}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3C51A368-C16C-4CE4-9BA6-E3B2BE211EBA}"
9+
ProjectSection(SolutionItems) = preProject
10+
..\common.props = ..\common.props
11+
EndProjectSection
712
EndProject
813
Global
914
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
2+
<Import Project="..\..\common.props" />
3+
34
<PropertyGroup>
45
<TargetFramework>netstandard2.1</TargetFramework>
56
<Nullable>enable</Nullable>
67
<RootNamespace>AndreasReitberger.Shared.XForm.Core</RootNamespace>
7-
<LangVersion>10</LangVersion>
8+
<LangVersion>10</LangVersion>
9+
10+
<Title>XForm-Core Shared Library</Title>
11+
<Description>A core libray used for our Xamarin.Forms libraries.</Description>
12+
<PackageTags> Xamarin, Forms, dotnet, NET, Standard, Core, Library, Helper, Preference</PackageTags>
13+
814
</PropertyGroup>
915

10-
<ItemGroup>
11-
<Compile Remove="Services\DeviceProviderService.Android.cs" />
12-
<Compile Remove="Services\DeviceProviderService.iOS.cs" />
13-
<Compile Remove="Services\PlatformThemeService.Android.cs" />
14-
<Compile Remove="Services\PlatformThemeService.iOS.cs" />
15-
</ItemGroup>
16+
<ItemGroup>
17+
<Compile Remove="Services\DeviceProviderService.Android.cs" />
18+
<Compile Remove="Services\DeviceProviderService.iOS.cs" />
19+
<Compile Remove="Services\PlatformThemeService.Android.cs" />
20+
<Compile Remove="Services\PlatformThemeService.iOS.cs" />
21+
</ItemGroup>
1622

1723
<ItemGroup>
1824
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
@@ -23,9 +29,9 @@
2329
</ItemGroup>
2430

2531
<ItemGroup>
26-
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
27-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
28-
<PackageReference Include="Xamarin.Essentials" Version="1.8.1" />
29-
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2622" />
32+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
33+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
34+
<PackageReference Include="Xamarin.Essentials" Version="1.8.1" />
35+
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2622" />
3036
</ItemGroup>
3137
</Project>

0 commit comments

Comments
 (0)