Sin*_*atr 5 c# wpf xaml vector-graphics
我想在 WPF 中使用矢量图形。
我有一堆 SVG 文件,可以使用 Inkscape 将其转换为 XAML。生成的 xamlResourceDictionary包含ViewBox/Canvas等Path。字典被合并到其中App.xaml,我可以使用 key 来访问它们。
问题:如何使用此类图像?看来我没有正确使用它们。
这是我如何使用它们
<Viewbox Child="{StaticResource MyImageResourceKey}" Width="100" Height="100"/>
Run Code Online (Sandbox Code Playgroud)
但看起来我只能使用一次(在一个地方)!尝试同时在多个位置使用该图像将把它从以前的位置删除或抛出
System.ArgumentException:在附加到新的父 Visual 之前,必须断开指定的子 Visual 与当前父 Visual 的连接。
我想显示矢量图像列表。我这样显示它们
<ItemsControl ItemsSource="{Binding Images}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Viewbox Width="100" Height="100">
<ContentPresenter Content="{Binding Image}"/>
</Viewbox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
视图模型
public class ViewModelSomeWindow : INotifyPropertyChanged
{
public class MyImage
{
public object Image { get; set; }
}
private ObservableCollection<MyImage> _images;
public ObservableCollection<MyImage> Images
{
get { return _images; }
set { _images = value; OnPropertyChanged(); }
}
...
}
Run Code Online (Sandbox Code Playgroud)
项目是这样添加的
Images.Add(new MyImage() { Image = App.Current.Resources["MyImageResourceKey"] });
Run Code Online (Sandbox Code Playgroud)
问题:当第二个项目使用相同的图像 ( ) 时,第一个项目显示(空白)图像。"MyImageResourceKey"如果图像已经使用StaticResource某处显示,那么添加项目将抛出上面的错误ArgumentException。
PS:我需要解决Y problem,但也许我没有正确使用矢量图形。
| 归档时间: |
|
| 查看次数: |
1509 次 |
| 最近记录: |