Skip to content

Commit

Permalink
Added property to view model
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaibatsu89 committed Jun 8, 2024
1 parent a1a3e3c commit f497cf1
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 53 deletions.
8 changes: 6 additions & 2 deletions samples/Plugin.Maui.Rotatable.Sample/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:c="clr-namespace:Plugin.Maui.Rotatable.Sample.Converters"
xmlns:vm="clr-namespace:Plugin.Maui.Rotatable.Sample.ViewModels"
Title="Rotatable Plugin">
Title="Rotatable Plugin"
x:DataType="{x:Type vm:MainPage}">
<ContentPage.BindingContext>
<vm:MainPage />
</ContentPage.BindingContext>
<Grid ColumnDefinitions="*,2*,*" ColumnSpacing="0">
<Grid Padding="10" BackgroundColor="Red">
<Grid
Padding="10"
BackgroundColor="Red"
IsVisible="{Binding IsAvailable}">
<Grid.Column>
<Binding Path="IsPortrait">
<Binding.Converter>
Expand Down
18 changes: 17 additions & 1 deletion samples/Plugin.Maui.Rotatable.Sample/ViewModels/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,21 @@

public class MainPage : RotatableImplementation
{

private bool _isAvailable = false;
public bool IsAvailable
{
get
{
return _isAvailable;
}
private set
{
SetProperty(ref _isAvailable, value);
}
}

public MainPage()
{
IsAvailable = true;
}
}
7 changes: 0 additions & 7 deletions src/Plugin.Maui.Rotatable/Plugin.Maui.Rotatable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@
<Compile Remove="**\windows\**\*.cs" />
<None Include="**\windows\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>
<!-- Tizen -->
<ItemGroup Condition="$(TargetFramework.StartsWith('net')) == true AND $(TargetFramework.Contains('-tizen')) != true">
<Compile Remove="**\*.samsung.cs" />
<None Include="**\*.samsung.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
<Compile Remove="**\samsung\**\*.cs" />
<None Include="**\samsung\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>
<!-- .NET (generic) -->
<ItemGroup Condition="!($(TargetFramework.StartsWith('net')) == true AND $(TargetFramework.EndsWith('.0')) == true AND $(TargetFramework.Contains('-')) != true)">
<!-- e.g net6.0 or net8.0 (and higher) -->
Expand Down
14 changes: 14 additions & 0 deletions src/Plugin.Maui.Rotatable/Rotatable.android.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Plugin.Maui.Rotatable;

Expand Down Expand Up @@ -40,4 +42,16 @@ private void OnWindowInfoChanged(object? sender, DisplayInfoChangedEventArgs e)
}

public event PropertyChangedEventHandler? PropertyChanged;

protected bool SetProperty<T>([NotNullIfNotNull(nameof(newValue))] ref T field, T newValue, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, newValue))
{
return false;
}

field = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
return true;
}
}
14 changes: 14 additions & 0 deletions src/Plugin.Maui.Rotatable/Rotatable.macios.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Plugin.Maui.Rotatable;

Expand Down Expand Up @@ -40,4 +42,16 @@ private void OnWindowInfoChanged(object? sender, DisplayInfoChangedEventArgs e)
}

public event PropertyChangedEventHandler? PropertyChanged;

protected bool SetProperty<T>([NotNullIfNotNull(nameof(newValue))] ref T field, T newValue, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, newValue))
{
return false;
}

field = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
return true;
}
}
43 changes: 0 additions & 43 deletions src/Plugin.Maui.Rotatable/Rotatable.samsung.cs

This file was deleted.

14 changes: 14 additions & 0 deletions src/Plugin.Maui.Rotatable/Rotatable.windows.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Plugin.Maui.Rotatable;

Expand Down Expand Up @@ -66,4 +68,16 @@ private void OnWindowInfoChanged(object? sender, DisplayInfoChangedEventArgs e)
}

public event PropertyChangedEventHandler? PropertyChanged;

protected bool SetProperty<T>([NotNullIfNotNull(nameof(newValue))] ref T field, T newValue, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, newValue))
{
return false;
}

field = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
return true;
}
}

0 comments on commit f497cf1

Please sign in to comment.