前提・実現したいこと
WPFアプリでXaml Islandを使用して
UWPのImageコントロールにSVG画像を表示したい。
環境:WPF,.NETCore3.0
発生している問題・エラーメッセージ
エラーはありませんが、SVG画像が表示されない。
該当のソースコード
Xaml
1<Window x:Class="XamlIslandsTest.Views.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:xamlhost="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost" 5 xmlns:prism="http://prismlibrary.com/" 6 prism:ViewModelLocator.AutoWireViewModel="True" 7 Title="{Binding Title}" Height="350" Width="525" > 8 <Grid> 9 <xamlhost:WindowsXamlHost InitialTypeName="Windows.UI.Xaml.Controls.Image" x:Name="Image" ChildChanged="Image_ChildChanged"/> 10 </Grid> 11</Window>
C#
1 public partial class MainWindow : Window 2 { 3 public MainWindow() 4 { 5 InitializeComponent(); 6 } 7 8 private void Image_ChildChanged(object sender, System.EventArgs e) 9 { 10 WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; 11 Windows.UI.Xaml.Controls.Image image = 12 (Windows.UI.Xaml.Controls.Image)windowsXamlHost.Child; 13 if(image != null) 14 { 15 var fileUri = "ms-appx:///Assets/windows.svg"; 16 SvgImageSource svgImage = new SvgImageSource(new Uri(fileUri)); 17 image.Source = svgImage; 18 } 19 } 20 }
svg
1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<svg width="20px" height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 3 <title>windows [#174]</title> 4 <desc>Created with Sketch.</desc> 5 <defs></defs> 6 <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> 7 <g id="Dribbble-Dark-Preview" transform="translate(-60.000000, -7439.000000)" fill="#18FF94"> 8 <g id="icons" transform="translate(56.000000, 160.000000)"> 9 <path d="M13.1458647,7289.43426 C13.1508772,7291.43316 13.1568922,7294.82929 13.1619048,7297.46884 C16.7759398,7297.95757 20.3899749,7298.4613 23.997995,7299 C23.997995,7295.84873 24.002005,7292.71146 23.997995,7289.71311 C20.3809524,7289.71311 16.7649123,7289.43426 13.1458647,7289.43426 M4,7289.43526 L4,7296.22153 C6.72581454,7296.58933 9.45162907,7296.94113 12.1724311,7297.34291 C12.1774436,7294.71736 12.1704261,7292.0908 12.1704261,7289.46524 C9.44661654,7289.47024 6.72380952,7289.42627 4,7289.43526 M4,7281.84344 L4,7288.61071 C6.72581454,7288.61771 9.45162907,7288.57673 12.1774436,7288.57973 C12.1754386,7285.96017 12.1754386,7283.34361 12.1724311,7280.72405 C9.44461153,7281.06486 6.71679198,7281.42567 4,7281.84344 M24,7288.47179 C20.3879699,7288.48578 16.7759398,7288.54075 13.1619048,7288.55175 C13.1598997,7285.88921 13.1598997,7283.22967 13.1619048,7280.56914 C16.7689223,7280.01844 20.3839599,7279.50072 23.997995,7279 C24,7282.15826 23.997995,7285.31353 24,7288.47179" id="windows-[#174]"></path> 10 </g> 11 </g> 12 </g> 13</svg>
試したこと
UWPで上記svgは正常に表示できました。
Xaml
1<Page 2 x:Class="UwpApp1.MainPage" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:local="using:UwpApp1" 6 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 7 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 8 mc:Ignorable="d" 9 Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 10 11 <Grid Margin="10,50,10,10" > 12 <Image Name="image" Height="20"/> 13 </Grid> 14</Page> 15
C#
1 public sealed partial class MainPage : Page 2 { 3 public MainPage() 4 { 5 this.InitializeComponent(); 6 7 this.Loaded += (s, e) => 8 { 9 var fileUri = "ms-appx:///Assets/windows.svg"; 10 SvgImageSource svgImage = new SvgImageSource(new Uri(fileUri)); 11 image.Source = svgImage; 12 13 }; 14 } 15 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/12/06 23:54
2020/12/07 00:32
2020/12/07 02:39 編集