-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
235 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="CheckMemoryLeak.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:CheckMemoryLeak" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Windows; | ||
|
||
namespace CheckMemoryLeak | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFrameworks>$(SampleTargetFrameworks)</TargetFrameworks> | ||
<Nullable>enable</Nullable> | ||
<UseWPF>true</UseWPF> | ||
<IsPackable>False</IsPackable> | ||
<LangVersion>9</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\MdXaml.Full\MdXaml.Full.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<Window x:Class="CheckMemoryLeak.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:CheckMemoryLeak" | ||
mc:Ignorable="d" | ||
Title="MainWindow" Height="450" Width="800"> | ||
|
||
<Window.DataContext> | ||
<local:MainWindowViewModel/> | ||
</Window.DataContext> | ||
|
||
<DockPanel LastChildFill="True"> | ||
<DockPanel LastChildFill="True"> | ||
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal"> | ||
<Button Content="Add Text" Command="{Binding AddTextCommand}"/> | ||
<Button Content="Add Resource" Margin="10,0,0,0" Command="{Binding AddResourceCommand}"/> | ||
</StackPanel> | ||
|
||
<Button DockPanel.Dock="Bottom" Content="Run" Click="Button_Click"/> | ||
|
||
<ListBox ItemsSource="{Binding Contents}"> | ||
<ListBox.ItemTemplate> | ||
<DataTemplate > | ||
<StackPanel Orientation="Horizontal"> | ||
<Label Width="90"> | ||
<Label.Style> | ||
<Style TargetType="Label"> | ||
<Style.Triggers> | ||
<DataTrigger Binding="{Binding ContentType}" Value="Resource"> | ||
<Setter Property="Content" Value="Resource"/> | ||
</DataTrigger> | ||
<DataTrigger Binding="{Binding ContentType}" Value="Text"> | ||
<Setter Property="Content" Value="Text"/> | ||
</DataTrigger> | ||
</Style.Triggers> | ||
</Style> | ||
</Label.Style> | ||
</Label> | ||
<TextBox Text="{Binding Text}" HorizontalAlignment="Stretch" Width="200"/> | ||
</StackPanel> | ||
</DataTemplate> | ||
</ListBox.ItemTemplate> | ||
</ListBox> | ||
</DockPanel> | ||
|
||
<DockPanel LastChildFill="True" x:Name="ViewPanel"> | ||
|
||
</DockPanel> | ||
</DockPanel> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using MdXaml.Full; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace CheckMemoryLeak | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private async void Button_Click(object sender, RoutedEventArgs e) | ||
{ | ||
var vm = (MainWindowViewModel)DataContext; | ||
foreach (var content in vm.Contents) | ||
{ | ||
var viewer = new MarkdownScrollViewer(); | ||
|
||
if (content.ContentType == ContentType.Resource) | ||
{ | ||
viewer.Source = new Uri(content.Text); | ||
} | ||
if (content.ContentType == ContentType.Text) | ||
{ | ||
viewer.Markdown = content.Text; | ||
} | ||
|
||
ViewPanel.Children.Add(viewer); | ||
|
||
while (!viewer.IsLoaded) | ||
await Task.Delay(1000); | ||
|
||
await Task.Delay(1000); | ||
|
||
ViewPanel.Children.Clear(); | ||
} | ||
|
||
foreach (var i in Enumerable.Range(0, 10)) { | ||
GC.Collect(); | ||
await Task.Delay(1000); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Data; | ||
using System.Net.Mime; | ||
using System.Text; | ||
using System.Windows.Input; | ||
|
||
namespace CheckMemoryLeak | ||
{ | ||
internal class MainWindowViewModel | ||
{ | ||
public ICommand AddTextCommand { get; } | ||
public ICommand AddResourceCommand { get; } | ||
|
||
public ObservableCollection<Content> Contents { get; } | ||
public MainWindowViewModel() | ||
{ | ||
Contents = new(); | ||
AddTextCommand = new DelegateCommand(AddText); | ||
AddResourceCommand = new DelegateCommand(AddResource); | ||
|
||
Contents.Add(new Content(ContentType.Resource) { Text = "https://raw.githubusercontent.com/whistyun/MdXaml/master/samples/MdXaml.Demo/MainWindow.md#note" }); | ||
Contents.Add(new Content(ContentType.Resource) { Text = @"file:///D:\MdXaml\samples\MdXaml.Demo\MainWindow.md#note" }); | ||
Contents.Add(new Content(ContentType.Text) { Text = @"[text](file:///D:\MdXaml\samples\MdXaml.Demo\MainWindow.md#note)" }); | ||
} | ||
|
||
public void AddText() | ||
{ | ||
Contents.Add(new Content(ContentType.Text)); | ||
} | ||
public void AddResource() | ||
{ | ||
Contents.Add(new Content(ContentType.Resource)); | ||
} | ||
} | ||
|
||
public class DelegateCommand : ICommand | ||
{ | ||
private Action _action; | ||
public event EventHandler? CanExecuteChanged; | ||
|
||
public DelegateCommand(Action act) | ||
{ | ||
_action = act; | ||
} | ||
|
||
public bool CanExecute(object? parameter) | ||
{ | ||
return true; | ||
} | ||
|
||
public void Execute(object? parameter) | ||
{ | ||
_action(); | ||
} | ||
} | ||
|
||
public class Content | ||
{ | ||
public ContentType ContentType { get; } | ||
public string Text { get; set; } | ||
|
||
public Content(ContentType type) | ||
{ | ||
ContentType = type; | ||
} | ||
} | ||
|
||
public enum ContentType | ||
{ | ||
Resource, | ||
Text | ||
} | ||
} |