-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
basic sample pages
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:markdownView="clr-namespace:Plugin.Maui.MarkdownView;assembly=Plugin.Maui.MarkdownView" | ||
x:Class="Plugin.Maui.MarkdownView.Sample.Pages.MarkdownFromFilePage" | ||
Title="MarkdownFromFilePage"> | ||
|
||
<ScrollView> | ||
<markdownView:MarkdownView x:Name="MarkdownView" /> | ||
</ScrollView> | ||
|
||
</ContentPage> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Plugin.Maui.MarkdownView.Sample.Pages; | ||
|
||
public partial class MarkdownFromFilePage : ContentPage | ||
{ | ||
public MarkdownFromFilePage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
protected override async void OnAppearing() | ||
{ | ||
base.OnAppearing(); | ||
|
||
await using var stream = await FileSystem.OpenAppPackageFileAsync("LorumMarkdown.md"); | ||
using var reader = new StreamReader(stream); | ||
var markdown = await reader.ReadToEndAsync(); | ||
|
||
MarkdownView.MarkdownText = markdown; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:markdownView="clr-namespace:Plugin.Maui.MarkdownView;assembly=Plugin.Maui.MarkdownView" | ||
x:Class="Plugin.Maui.MarkdownView.Sample.Pages.MarkdownFromRemotePage" | ||
Title="MarkdownFromRemotePage"> | ||
|
||
<RefreshView x:Name="RefreshView" Refreshing="OnRefreshing" > | ||
<ScrollView> | ||
<markdownView:MarkdownView x:Name="MarkdownView" /> | ||
</ScrollView> | ||
</RefreshView> | ||
|
||
</ContentPage> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
namespace Plugin.Maui.MarkdownView.Sample.Pages; | ||
|
||
public partial class MarkdownFromRemotePage : ContentPage | ||
{ | ||
private const string RemoteFile = "https://enbyin.com/resources/MarkdownExample.md"; | ||
|
||
public MarkdownFromRemotePage() | ||
{ | ||
InitializeComponent(); | ||
|
||
SetRemoteBasePathForResources(); | ||
} | ||
|
||
private void SetRemoteBasePathForResources() | ||
{ | ||
// To work with online images and other resources | ||
// 1. determine images/resources base path | ||
// 2. create and set new IViewSupplier that works with the base path | ||
// 3. set some (prefix) paths that the system can ignore when converting relative paths | ||
|
||
var remoteFile = new Uri(RemoteFile); | ||
var basePathRemoteFile = string.Format("{0}{1}" | ||
, remoteFile.GetLeftPart(UriPartial.Authority) | ||
, string.Join(string.Empty, | ||
remoteFile.Segments.Take(remoteFile.Segments.Length - 1))); | ||
|
||
MarkdownView.ViewSupplier = new MauiViewSupplier | ||
{ | ||
BasePathForRelativeUrlConversion = basePathRemoteFile, | ||
PrefixesToIgnoreForRelativeUrlConversion = Array.Empty<string>() | ||
}; | ||
} | ||
|
||
protected override void OnAppearing() | ||
{ | ||
base.OnAppearing(); | ||
RefreshView.IsRefreshing = true; | ||
} | ||
|
||
private async void OnRefreshing(object? sender, EventArgs e) | ||
{ | ||
await LoadMarkdownFromRemote(); | ||
RefreshView.IsRefreshing = false; | ||
} | ||
|
||
private async Task LoadMarkdownFromRemote() | ||
{ | ||
try | ||
{ | ||
using var http = new HttpClient(); | ||
var markdown = await http.GetStringAsync(RemoteFile); | ||
|
||
MarkdownView.MarkdownText = markdown; | ||
} | ||
catch (Exception e) | ||
Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs
|
||
{ | ||
MarkdownView.MarkdownText = $"__error: wasn't able to retrieve '{RemoteFile}'__"; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Plugin.Maui.MarkdownView.Sample.Pages; | ||
|
||
public partial class MarkdownInXamlPage : ContentPage | ||
{ | ||
public MarkdownInXamlPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |