如何添加画布XAML资源在用户控件 [英] How to add canvas xaml resource in usercontrol

查看:121
本文介绍了如何添加画布XAML资源在用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载了这个包: http://modernuiicons.com/ ,我尝试使用XAML图标。



我添加了一个XAML文件,我有以下内容

 <

解决方案

C $ C><?XML版本=1.0编码=UTF-8>?;
<帆布的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml× :NAME =appbar_checkWIDTH =76HEIGHT =76剪辑=F1中号0,0L 76,0L 76,76L 0,76L 0,0>
<路径宽度=37.9998HEIGHT =31.6665Canvas.Left =19.0001Canvas.Top =22.1668拉伸=填充填充=#FF000000数据=F1中号23.7501,33.25大号34.8334,44.3333L 52.2499,22.1668L 56.9999,26.9168L 34.8334,53.8333L 19.0001,38L 23.7501,33.25 Z/>
< /帆布>

现在,我怎么引用这个画布我的用户?



用户控件



 <用户控件
的xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
的xmlns:D =http://schemas.microsoft.com/expression/blend/2008
的xmlns:MC =http://schemas.openxmlformats.org/markup-compatibility/2006
的xmlns:我=http://schemas.microsoft.com/expression/2010/interactivity的xmlns:EI =http://schemas.microsoft.com/expression/2010/interactions
MC:可忽略=D
X:类=UserControlSolution.UserControlButton
X:名称=用户控件
高度=50背景=#FF2F2F2FBorderBrush =#FF919191>


<电网X:NAME =LayoutRootHEIGHT =50RenderTransformOrigin =0.5,0.5>
<矩形X:NAME =矩形RenderTransformOrigin =0.5,0.5WIDTH =230HEIGHT =50/>
< TextBlock的X:名称=NameLabel字号=16前景=#FFE5E5E5HEIGHT =34WIDTH =149文本=Onthaal TelefoonVerticalAlignment =顶部的Horizo​​ntalAlignment =左保证金=10,10,0,0的FontFamily =濑越UI Semibold/>
< Viewbox控件的Horizo​​ntalAlignment =右VerticalAlignment =评出的HEIGHT =16.5WIDTH =17.789保证金=0,15,24.5,0>
//这里我想引用画布
< / Viewbox控件>
< /网格和GT;
< /用户控件>



我可以复制画布offcourse的内容,但必须有另一种解决方案。


解决方案

添加画布路径作为页面的App.xaml或什么的,记得设置<上或资源$ C ​​$ C> X:键。然后用 ContentControl中来引用资源

 <! -  - 在资源,无论是在页面或App.xaml中的应用范围重用 - > 
<帆布X:键=TickCanvas的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation的xmlns:X =http://schemas.microsoft.com/ WinFX的/ 2006 / XAMLX:NAME =appbar_checkWIDTH =76HEIGHT =76剪辑=F1中号0,0L 76,0L 76,76L 0,76L 0,0>
<路径宽度=37.9998HEIGHT =31.6665Canvas.Left =19.0001Canvas.Top =22.1668拉伸=填充填充=#FF000000数据=F1中号23.7501,33.25大号34.8334,44.3333L 52.2499,22.1668L 56.9999,26.9168L 34.8334,53.8333L 19.0001,38L 23.7501,33.25 Z/>
< /帆布

<! - 在您的网页,或者某个地方 - >
<&视框GT;
< ContentControl中CONTENT ={StaticResource的TickCanvas}/>
< /视框>



为了证明它的作品,我能看到它打勾!



只是一个方面说明,我经常只是路径数据,迷你标记和保存为一个字符串资源。然后使用Data = {StaticResource的TickPath} 这样我可以调整矢量使用路径我通过引用标记资源在身高宽度路径本身还是让它扩大并通过设置拉伸=统一由其父萎缩。 。保存 Viewbox控件的开销

 <! - 在App.xaml中的应用范围重用 - > 
< X:字符串x:键=TickPath> F1中号23.7501,33.25L 34.8334,44.3333L 52.2499,22.1668L 56.9999,26.9168L 34.8334,53.8333L 19.0001,38L 23.7501,33.25 z,其中,/ X:字符串>

<! - 在页面模板或是其他地方 - >
<路径数据={StaticResource的TickPath} />

这方法可能不。在这种情况下,因为一个片段的几何形状存在,但对于简单的向量的很好,我有手绘字体(不能嵌入字体)存储为标记的文件工作,然后我加载它们在运行时 - 数据= {结合PathData} 作品一样好。


I have downloaded this pack : http://modernuiicons.com/ and I'm trying to use the xaml icons.

I have added a xaml file to my solution with the following content

<?xml version="1.0" encoding="utf-8"?>
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_check" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
<Path Width="37.9998" Height="31.6665" Canvas.Left="19.0001" Canvas.Top="22.1668" Stretch="Fill" Fill="#FF000000" Data="F1 M 23.7501,33.25L 34.8334,44.3333L 52.2499,22.1668L 56.9999,26.9168L 34.8334,53.8333L 19.0001,38L 23.7501,33.25 Z "/>
</Canvas>

Now, how do I reference this canvas to my usercontrol?

Usercontrol

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
mc:Ignorable="d"
x:Class="UserControlSolution.UserControlButton"
x:Name="UserControl"
Height="50" Background="#FF2F2F2F" BorderBrush="#FF919191">


<Grid x:Name="LayoutRoot" Height="50" RenderTransformOrigin="0.5,0.5">
    <Rectangle x:Name="rectangle" RenderTransformOrigin="0.5,0.5" Width="230" Height="50"/>
    <TextBlock x:Name="NameLabel" FontSize="16" Foreground="#FFE5E5E5" Height="34" Width="149" Text="Onthaal Telefoon" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,10,0,0" FontFamily="Segoe UI Semibold"/>
    <Viewbox HorizontalAlignment="Right" VerticalAlignment="Top" Height="16.5" Width="17.789" Margin="0,15,24.5,0">
        // Here I want to reference the canvas
    </Viewbox>
</Grid>
</UserControl>

I can copy the content of the canvas offcourse but there must be another solution.

解决方案

Add the Canvas and Path as a resource on the page or in the App.xaml or whatever, remember to set x:Key. Then use a ContentControl to reference the resource.

<!-- In Resources, either on the Page or App.xaml for app-wide reuse -->
<Canvas x:Key="TickCanvas" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_check" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
    <Path Width="37.9998" Height="31.6665" Canvas.Left="19.0001" Canvas.Top="22.1668" Stretch="Fill" Fill="#FF000000" Data="F1 M 23.7501,33.25L 34.8334,44.3333L 52.2499,22.1668L 56.9999,26.9168L 34.8334,53.8333L 19.0001,38L 23.7501,33.25 Z "/>
</Canvas

<!-- On your page, or somewhere -->
<ViewBox>
    <ContentControl Content="{StaticResource TickCanvas}" />
</ViewBox>

As proof it works, I was able to see its a tick!

Just a side note, I often take just the path data, the mini-markup and save that as a string resource. Then using a Path I reference the markup resource via Data={StaticResource TickPath} that way I can resize the vector using the Height and Width on the Path itself or let it expand and shrink by its parent by setting Stretch="Uniform". Saves the overhead of the Viewbox.

<!-- In App.xaml for app-wide reuse -->
<x:String x:Key="TickPath">F1 M 23.7501,33.25L 34.8334,44.3333L 52.2499,22.1668L 56.9999,26.9168L 34.8334,53.8333L 19.0001,38L 23.7501,33.25 Z </x:String>

<!-- On page, template or wherever -->
<Path Data="{StaticResource TickPath} />

This technique may not work in this instance as there's a clip geometry there. But for simple vectors its fine, I have hand drawn typefaces (that can't be embedded as fonts) stored as markup in files, I then load them in at runtime - Data={Binding PathData} works just as well.

这篇关于如何添加画布XAML资源在用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆