-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathMainWindow.axaml.cs
More file actions
87 lines (79 loc) · 2.97 KB
/
Copy pathMainWindow.axaml.cs
File metadata and controls
87 lines (79 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MainWindow.xaml.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// <summary>
// Interaction logic for MainWindow.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------
using Avalonia.Input;
using Avalonia.Media.Imaging;
namespace AvaloniaExamples
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Interactivity;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
/// <summary>
/// Initializes a new instance of the <see cref="MainWindow" /> class.
/// </summary>
public MainWindow()
{
InitializeComponent();
ListBox.ItemsSource = this.Examples = this.GetExamples(this.GetType().Assembly).OrderBy(e => e.Title).ToArray();
this.DataContext = this;
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
ListBox = this.Find<ListBox>(nameof(ListBox));
ListBox.DoubleTapped += ListBoxMouseDoubleClick;
}
/// <summary>
/// Gets the examples.
/// </summary>
/// <value>The examples.</value>
public IList<Example> Examples { get; private set; }
/// <summary>
/// Handles the MouseDoubleClick event of the ListBox control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs" /> instance containing the event data.</param>
private void ListBoxMouseDoubleClick(object sender, RoutedEventArgs e)
{
var lb = (ListBox)sender;
var example = lb.SelectedItem as Example;
if (example != null)
{
var window = example.Create();
window.Icon = this.Icon;
window.Show(this);
}
}
/// <summary>
/// Gets the examples in the specified assembly.
/// </summary>
/// <param name="assembly">The assembly to scan.</param>
/// <returns>A sequence of <see cref="Example" /> objects.</returns>
private IEnumerable<Example> GetExamples(Assembly assembly)
{
foreach (var type in assembly.GetTypes())
{
var ea = type.GetCustomAttributes(typeof(ExampleAttribute), false).FirstOrDefault() as ExampleAttribute;
if (ea != null)
{
yield return new Example(type, ea.Title, ea.Description);
}
}
}
}
}