5 changed files with 95 additions and 0 deletions
|
After Width: | Height: | Size: 1.3 KiB |
@ -0,0 +1,29 @@ |
|||
<UserControl xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
x:Class="ControlCatalog.Pages.CursorPage"> |
|||
<Grid ColumnDefinitions="*,*" RowDefinitions="Auto,*"> |
|||
<StackPanel Grid.ColumnSpan="2" Orientation="Vertical" Spacing="4"> |
|||
<TextBlock Classes="h1">Cursor</TextBlock> |
|||
<TextBlock Classes="h2">Defines a cursor (mouse pointer)</TextBlock> |
|||
</StackPanel> |
|||
|
|||
<ListBox Grid.Row="1" Items="{Binding StandardCursors}" Margin="0 8 8 8"> |
|||
<ListBox.Styles> |
|||
<Style Selector="ListBoxItem"> |
|||
<Setter Property="Cursor" Value="{Binding Cursor}"/> |
|||
</Style> |
|||
</ListBox.Styles> |
|||
<ListBox.ItemTemplate> |
|||
<DataTemplate> |
|||
<TextBlock Text="{Binding Type}"/> |
|||
</DataTemplate> |
|||
</ListBox.ItemTemplate> |
|||
</ListBox> |
|||
|
|||
<StackPanel Grid.Column="1" Grid.Row="1" Margin="8 8 0 8"> |
|||
<Button Cursor="{Binding CustomCursor}" Margin="0 8" Padding="16"> |
|||
<TextBlock>Custom Cursor</TextBlock> |
|||
</Button> |
|||
</StackPanel> |
|||
</Grid> |
|||
</UserControl> |
|||
@ -0,0 +1,20 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.Markup.Xaml; |
|||
using ControlCatalog.ViewModels; |
|||
|
|||
namespace ControlCatalog.Pages |
|||
{ |
|||
public class CursorPage : UserControl |
|||
{ |
|||
public CursorPage() |
|||
{ |
|||
this.InitializeComponent(); |
|||
DataContext = new CursorPageViewModel(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Avalonia; |
|||
using Avalonia.Input; |
|||
using Avalonia.Media.Imaging; |
|||
using Avalonia.Platform; |
|||
using ReactiveUI; |
|||
|
|||
namespace ControlCatalog.ViewModels |
|||
{ |
|||
public class CursorPageViewModel : ReactiveObject |
|||
{ |
|||
public CursorPageViewModel() |
|||
{ |
|||
StandardCursors = Enum.GetValues(typeof(StandardCursorType)) |
|||
.Cast<StandardCursorType>() |
|||
.Select(x => new StandardCursorModel(x)) |
|||
.ToList(); |
|||
|
|||
var loader = AvaloniaLocator.Current.GetService<IAssetLoader>(); |
|||
var s = loader.Open(new Uri("avares://ControlCatalog/Assets/avalonia-32.png")); |
|||
var bitmap = new Bitmap(s); |
|||
CustomCursor = new Cursor(bitmap, new PixelPoint(16, 16)); |
|||
} |
|||
|
|||
public IEnumerable<StandardCursorModel> StandardCursors { get; } |
|||
public Cursor CustomCursor { get; } |
|||
|
|||
public class StandardCursorModel |
|||
{ |
|||
public StandardCursorModel(StandardCursorType type) |
|||
{ |
|||
Type = type; |
|||
Cursor = new Cursor(type); |
|||
} |
|||
|
|||
public StandardCursorType Type { get; } |
|||
public Cursor Cursor { get; } |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue