|
| 1 | +<?xml version="1.0" encoding="utf-8" ?> |
| 2 | +<Page |
| 3 | + x:Class="WinUI3Example.SvgPage" |
| 4 | + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| 5 | + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| 6 | + xmlns:Foundation="using:Windows.Foundation" |
| 7 | + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
| 8 | + xmlns:essential="using:WinUI3Package" |
| 9 | + xmlns:local="using:WinUI3Example" |
| 10 | + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
| 11 | + xmlns:svg="using:WinUI3Package.Svg" |
| 12 | + mc:Ignorable="d"> |
| 13 | + |
| 14 | + <StackPanel Style="{StaticResource ControlExamplesStackPanelStyle}"> |
| 15 | + <local:ControlExample HeaderText="Paste in svg urls"> |
| 16 | + <Grid ColumnSpacing="8"> |
| 17 | + <Grid.ColumnDefinitions> |
| 18 | + <ColumnDefinition Width="*" /> |
| 19 | + <ColumnDefinition Width="*" /> |
| 20 | + </Grid.ColumnDefinitions> |
| 21 | + |
| 22 | + <essential:GroupBox Header="WinUIEssential.Svg"> |
| 23 | + <Image |
| 24 | + x:Name="SvgUrlImage" |
| 25 | + MinWidth="500" |
| 26 | + MinHeight="500"> |
| 27 | + <Image.Source> |
| 28 | + <svg:SvgImageSource BindSizeTo="{x:Bind SvgUrlImage}" UriSource="{x:Bind SvgUrl.Text, Mode=OneWay}" /> |
| 29 | + </Image.Source> |
| 30 | + </Image> |
| 31 | + </essential:GroupBox> |
| 32 | + |
| 33 | + <essential:GroupBox Grid.Column="1" Header="WinUI3 Image"> |
| 34 | + <Image MinWidth="500" MinHeight="500"> |
| 35 | + <Image.Source> |
| 36 | + <SvgImageSource UriSource="{x:Bind SvgUrl.Text, Mode=OneWay}" /> |
| 37 | + </Image.Source> |
| 38 | + </Image> |
| 39 | + </essential:GroupBox> |
| 40 | + </Grid> |
| 41 | + <local:ControlExample.Options> |
| 42 | + <TextBox |
| 43 | + x:Name="SvgUrl" |
| 44 | + Width="400" |
| 45 | + PlaceholderText="Paste svg url here to test the rendering effect" |
| 46 | + Text="https://img.shields.io/nuget/v/WinUIEssential.WinUI3?label=WinUIEssential.WinUI3" |
| 47 | + TextWrapping="Wrap" /> |
| 48 | + </local:ControlExample.Options> |
| 49 | + |
| 50 | + <local:ControlExample.Xaml> |
| 51 | + <local:CodeSource> |
| 52 | + <local:CodeSource.Code> |
| 53 | + <x:String xml:space="preserve">xmlns:svg="using:WinUI3Package.Svg" |
| 54 | +<Image |
| 55 | + x:Name="SvgUrlImage" |
| 56 | + MinWidth="500" |
| 57 | + MinHeight="500"> |
| 58 | + <Image.Source> |
| 59 | + <svg:SvgImageSource BindSizeTo="{x:Bind SvgUrlImage}" UriSource="https://img.shields.io/nuget/v/WinUIEssential.WinUI3?label=WinUIEssential.WinUI3 /> |
| 60 | + </Image.Source> |
| 61 | +</Image> |
| 62 | + |
| 63 | +<!-- Drop-in replacement for winui3's built-in SvgImageSource --> |
| 64 | +<Image MinWidth="500" MinHeight="500"> |
| 65 | + <Image.Source> |
| 66 | + <SvgImageSource UriSource="https://img.shields.io/nuget/v/WinUIEssential.WinUI3?label=WinUIEssential.WinUI3 /> |
| 67 | + </Image.Source> |
| 68 | +</Image></x:String> |
| 69 | + </local:CodeSource.Code> |
| 70 | + </local:CodeSource> |
| 71 | + </local:ControlExample.Xaml> |
| 72 | + </local:ControlExample> |
| 73 | + |
| 74 | + <local:ControlExample HeaderText="Paste in svg strings"> |
| 75 | + <Grid ColumnSpacing="8"> |
| 76 | + <Grid.ColumnDefinitions> |
| 77 | + <ColumnDefinition Width="*" /> |
| 78 | + <ColumnDefinition Width="*" /> |
| 79 | + </Grid.ColumnDefinitions> |
| 80 | + |
| 81 | + <essential:GroupBox Header="WinUI3Essential.Svg"> |
| 82 | + <Image |
| 83 | + x:Name="SvgStringImage" |
| 84 | + MinWidth="500" |
| 85 | + MinHeight="500"> |
| 86 | + <Image.Source> |
| 87 | + <svg:SvgImageSource BindSizeTo="{x:Bind SvgStringImage}" StringSource="{x:Bind SvgString.Text, Mode=OneWay}" /> |
| 88 | + </Image.Source> |
| 89 | + </Image> |
| 90 | + </essential:GroupBox> |
| 91 | + |
| 92 | + <essential:GroupBox Grid.Column="1" Header="WinUI3 Image"> |
| 93 | + <!-- Native SvgImageSource does not support rendering from a string, you have to use a Converter or functional binding --> |
| 94 | + <Image |
| 95 | + MinWidth="500" |
| 96 | + MinHeight="500" |
| 97 | + Source="{x:Bind local:SvgPage.GetSvgImageSourceFromString(SvgString.Text), Mode=OneWay}" /> |
| 98 | + </essential:GroupBox> |
| 99 | + </Grid> |
| 100 | + |
| 101 | + |
| 102 | + <local:ControlExample.Options> |
| 103 | + <TextBox |
| 104 | + x:Name="SvgString" |
| 105 | + Width="400" |
| 106 | + AcceptsReturn="True" |
| 107 | + PlaceholderText="Paste svg string here to test the rendering effect" |
| 108 | + TextWrapping="Wrap"> |
| 109 | + <TextBox.Text> |
| 110 | + <x:String xml:space="preserve"><svg xmlns="http://www.w3.org/2000/svg" width="168" height="20" role="img" aria-label="WinUIEssential.UWP: v1.3.3"> |
| 111 | + <title>WinUIEssential.UWP: v1.3.3</title> |
| 112 | + <filter id="blur"> |
| 113 | + <feGaussianBlur in="SourceGraphic" stdDeviation="16"/> |
| 114 | + </filter> |
| 115 | + <linearGradient id="s" x2="0" y2="100%"> |
| 116 | + <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> |
| 117 | + <stop offset="1" stop-opacity=".1"/> |
| 118 | + </linearGradient> |
| 119 | + <clipPath id="r"> |
| 120 | + <rect width="168" height="20" rx="3" fill="#fff"/> |
| 121 | + </clipPath> |
| 122 | + <g clip-path="url(#r)"> |
| 123 | + <rect width="123" height="20" fill="#555"/> |
| 124 | + <rect x="123" width="45" height="20" fill="#007ec6"/> |
| 125 | + <rect width="168" height="20" fill="url(#s)"/> |
| 126 | + </g> |
| 127 | + <g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"> |
| 128 | + <text aria-hidden="true" x="625" y="150" fill="#010101" fill-opacity=".80" filter="url(#blur)" transform="scale(.1)" textLength="1130">WinUIEssential.UWP</text> |
| 129 | + <text aria-hidden="true" x="625" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="1130">WinUIEssential.UWP</text> |
| 130 | + <text x="625" y="140" transform="scale(.1)" fill="#fff" textLength="1130">WinUIEssential.UWP</text> |
| 131 | + <text aria-hidden="true" x="1445" y="150" fill="#010101" fill-opacity=".80" filter="url(#blur)" transform="scale(.1)" textLength="350">v1.3.3</text> |
| 132 | + <text aria-hidden="true" x="1445" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="350">v1.3.3</text> |
| 133 | + <text x="1445" y="140" transform="scale(.1)" fill="#fff" textLength="350">v1.3.3</text> |
| 134 | + </g> |
| 135 | +</svg></x:String> |
| 136 | + </TextBox.Text> |
| 137 | + </TextBox> |
| 138 | + </local:ControlExample.Options> |
| 139 | + |
| 140 | + <local:ControlExample.Xaml> |
| 141 | + <local:CodeSource> |
| 142 | + <local:CodeSource.Code> |
| 143 | + <x:String xml:space="preserve">xmlns:svg="using:WinUI3Package.Svg" |
| 144 | +<!-- Binding to a svg string is also supported --> |
| 145 | +<Image |
| 146 | + x:Name="SvgStringImage" |
| 147 | + MinWidth="500" |
| 148 | + MinHeight="500"> |
| 149 | + <Image.Source> |
| 150 | + <svg:SvgImageSource BindSizeTo="{x:Bind SvgStringImage}" StringSource="{x:Bind SvgString.Text, Mode=OneWay}" /> |
| 151 | + </Image.Source> |
| 152 | +</Image></x:String> |
| 153 | + </local:CodeSource.Code> |
| 154 | + </local:CodeSource> |
| 155 | + </local:ControlExample.Xaml> |
| 156 | + </local:ControlExample> |
| 157 | + |
| 158 | + <local:ControlExample HeaderText="WinUI3Package.Svg vs WinUI3 built-in Image vs expected png result"> |
| 159 | + |
| 160 | + <ListView |
| 161 | + x:Name="SvgListView" |
| 162 | + Grid.Column="0" |
| 163 | + MaxHeight="3000" |
| 164 | + ItemsSource="{x:Bind Svgs}" |
| 165 | + Tag="Svg"> |
| 166 | + <ListView.ItemTemplate> |
| 167 | + <DataTemplate x:DataType="Foundation:Uri"> |
| 168 | + <StackPanel Orientation="Horizontal" Spacing="8"> |
| 169 | + <StackPanel Spacing="8"> |
| 170 | + <Image |
| 171 | + Width="200" |
| 172 | + Height="200" |
| 173 | + Stretch="Uniform"> |
| 174 | + <Image.Source> |
| 175 | + <svg:SvgImageSource UriSource="{Binding}" /> |
| 176 | + </Image.Source> |
| 177 | + </Image> |
| 178 | + <TextBlock Text="{Binding}" /> |
| 179 | + </StackPanel> |
| 180 | + |
| 181 | + <StackPanel Spacing="8"> |
| 182 | + <Image |
| 183 | + Width="200" |
| 184 | + Height="200" |
| 185 | + Source="{Binding}" |
| 186 | + Stretch="Uniform" /> |
| 187 | + </StackPanel> |
| 188 | + |
| 189 | + <StackPanel Spacing="8"> |
| 190 | + <Image |
| 191 | + Width="200" |
| 192 | + Height="200" |
| 193 | + Stretch="Uniform"> |
| 194 | + <Image.Source> |
| 195 | + <BitmapImage UriSource="{x:Bind local:SvgPage.GetPngFromSvgUrl((Foundation:Uri))}" /> |
| 196 | + </Image.Source> |
| 197 | + </Image> |
| 198 | + <TextBlock Text="{x:Bind local:SvgPage.GetPngFromSvgUrl((Foundation:Uri))}" /> |
| 199 | + </StackPanel> |
| 200 | + </StackPanel> |
| 201 | + |
| 202 | + </DataTemplate> |
| 203 | + </ListView.ItemTemplate> |
| 204 | + </ListView> |
| 205 | + </local:ControlExample> |
| 206 | + |
| 207 | + </StackPanel> |
| 208 | +</Page> |
0 commit comments