|
| 1 | +@page "/mudgallery" |
| 2 | +@using MudBlazor.Extensions |
| 3 | +@using MudBlazor.Utilities |
| 4 | + |
| 5 | +<ExamplePage Title="MudGallery"> |
| 6 | + <ExampleCard Title="Usage" Description=""> |
| 7 | + <MudGrid> |
| 8 | + <MudItem xs="12" sm="8" Class="d-flex align-center flex-wrap"> |
| 9 | + <MudGallery @ref="_gallery" ImageSource="_source" ItemPerLine="_itemPerLine" EnableBackdropClick="_enableBackdropClick" |
| 10 | + ShowToolboxCloseButton="_showToolboxCloseButton" ShowToolboxNavigationButtons="_showToolboxNavigationButtons" |
| 11 | + MaxWidth="_maxWidth" StyleSelectedImage="@ImageStyle" EnableAnimation="_enableAnimation"> |
| 12 | + <ToolboxTopContent> |
| 13 | + <MudText Class="white-text pa-4">Image @(_gallery.GetSelectedImageIndex() + 1) - Description</MudText> |
| 14 | + </ToolboxTopContent> |
| 15 | + <ToolboxBottomContent> |
| 16 | + <MudIconButton Class="white-text" Icon="@Icons.Outlined.Edit" /> |
| 17 | + <MudIconButton Class="white-text" Icon="@Icons.Outlined.RotateRight" OnClick="ArrangeRotateValue" /> |
| 18 | + @if (_showToolboxCloseButton == false) |
| 19 | + { |
| 20 | + <MudIconButton Class="white-text" Icon="@Icons.Outlined.Close" OnClick="@(() => _gallery.ChangeMenu(false))" /> |
| 21 | + } |
| 22 | + </ToolboxBottomContent> |
| 23 | + </MudGallery> |
| 24 | + </MudItem> |
| 25 | + |
| 26 | + <MudItem xs="12" sm="4"> |
| 27 | + <MudStack Spacing="4"> |
| 28 | + <MudNumericField @bind-Value="_itemPerLine" Label="Item Per Line" /> |
| 29 | + <MudSwitch @bind-Checked="_enableBackdropClick" Color="Color.Primary" Label="Enable Backdrop Click" /> |
| 30 | + <MudSwitch @bind-Checked="_showToolboxCloseButton" Color="Color.Primary" Label="Toolbox Close Button" /> |
| 31 | + <MudSwitch @bind-Checked="_showToolboxNavigationButtons" Color="Color.Primary" Label="Toolbox Navigation Buttons" /> |
| 32 | + <MudSwitch @bind-Checked="_enableAnimation" Color="Color.Primary" Label="Animation" /> |
| 33 | + <MudSelect @bind-Value="_maxWidth" Variant="Variant.Outlined" Label="MaxWidth" Margin="Margin.Dense" Dense="true"> |
| 34 | + @foreach (MaxWidth item in Enum.GetValues<MaxWidth>()) |
| 35 | + { |
| 36 | + <MudSelectItem Value="item">@item.ToDescriptionString()</MudSelectItem> |
| 37 | + } |
| 38 | + </MudSelect> |
| 39 | + </MudStack> |
| 40 | + </MudItem> |
| 41 | + </MudGrid> |
| 42 | + </ExampleCard> |
| 43 | +</ExamplePage> |
| 44 | + |
| 45 | +@code{ |
| 46 | + MudGallery _gallery; |
| 47 | + int _itemPerLine = 3; |
| 48 | + bool _enableBackdropClick = true; |
| 49 | + bool _showToolboxCloseButton = true; |
| 50 | + bool _showToolboxNavigationButtons = true; |
| 51 | + bool _enableAnimation = true; |
| 52 | + int _rotateValue = 0; |
| 53 | + MaxWidth _maxWidth = MaxWidth.Medium; |
| 54 | + |
| 55 | + private string ImageStyle => new StyleBuilder() |
| 56 | + .AddStyle("transform", $"rotate({_rotateValue}deg)") |
| 57 | + .Build(); |
| 58 | + |
| 59 | + List<string> _source = new() { "https://cdn.pixabay.com/photo/2022/09/17/08/47/piano-7460435_960_720.jpg", |
| 60 | + "https://cdn.pixabay.com/photo/2017/07/29/16/10/windows-2551954_960_720.jpg", |
| 61 | + "https://mudblazor.com/images/castle.jpg", |
| 62 | + "https://cdn.pixabay.com/photo/2022/08/01/13/20/lily-of-the-valley-7358144__340.jpg", |
| 63 | + "https://cdn.pixabay.com/photo/2022/03/31/01/05/bird-7102006__340.jpg", |
| 64 | + "https://cdn.pixabay.com/photo/2019/06/05/08/37/dog-4253238__340.jpg", |
| 65 | + "https://cdn.pixabay.com/photo/2022/07/27/03/23/deer-7347041_960_720.jpg", |
| 66 | + "https://cdn.pixabay.com/photo/2022/03/31/11/28/snakes-head-fritillary-7102810_960_720.jpg", |
| 67 | + "https://cdn.pixabay.com/photo/2022/10/07/09/06/bridge-7504605_960_720.jpg", |
| 68 | + "https://cdn.pixabay.com/photo/2022/08/24/05/44/duck-7406987_960_720.jpg", |
| 69 | + "https://cdn.pixabay.com/photo/2022/10/05/20/43/hyacinth-macaw-7501470_960_720.jpg" }; |
| 70 | + |
| 71 | + private void ArrangeRotateValue() |
| 72 | + { |
| 73 | + if (_rotateValue == 270) |
| 74 | + { |
| 75 | + _rotateValue = 0; |
| 76 | + return; |
| 77 | + } |
| 78 | + _rotateValue += 90; |
| 79 | + } |
| 80 | +} |
0 commit comments