画布作为按钮WPF中的图像
我正在将项目中的所有图像移动到画布作为按钮WPF中的图像,wpf,image,xaml,button,canvas,Wpf,Image,Xaml,Button,Canvas,我正在将项目中的所有图像移动到ResourceDictionary中,以便在所有项目中使用。使用Syncfusion Metro Studio时,我能够获得图像的XAML源 <Viewbox x:Shared="false" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <Grid> <Grid Name="backgroundGrid" Width="48" Hei
ResourceDictionary
中,以便在所有项目中使用。使用Syncfusion Metro Studio时,我能够获得图像的XAML源
<Viewbox x:Shared="false" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Grid>
<Grid Name="backgroundGrid" Width="48" Height="48" Visibility="Collapsed" />
<Path Data="M0,4.1309996L20.362437,4.1309996C20.038338,4.8125897,19.782439,5.5301299,19.594339,6.2769008L2.1451931,6.2769008 2.1451931,23.445208 30.042807,23.445208 30.042807,20.78887C30.342306,20.81167 30.642406,20.834471 30.949104,20.834471 31.367603,20.834471 31.781102,20.81027 32.188001,20.76737L32.188001,25.590239 20.922435,25.590239 20.922435,27.736771 23.605427,27.736771 23.605427,29.882 8.5839529,29.882 8.5839529,27.736771 11.265565,27.736771 11.265565,25.590239 0,25.590239z M29.967411,3.9921243L29.967411,8.1359167 25.823251,8.1359167 25.823251,10.100034 29.967411,10.100034 29.967411,14.243865 31.931586,14.243865 31.931586,10.100034 36.075645,10.100034 36.075645,8.1359167 31.931586,8.1359167 31.931586,3.9921243z M30.948448,0C35.985142,1.0841802E-08 40.067997,4.0825729 40.067997,9.1171007 40.067997,14.153367 35.985142,18.236 30.948448,18.236 25.912456,18.236 21.830998,14.153367 21.830998,9.1171007 21.830998,4.0825729 25.912456,1.0841802E-08 30.948448,0z" Stretch="Uniform" Fill="#FF666666" Width="26" Height="26" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform Angle="0" />
<ScaleTransform ScaleX="1" ScaleY="1" />
</TransformGroup.Children>
</TransformGroup>
</Path.RenderTransform>
</Path>
</Grid>
</Viewbox>
这里的问题是,我正在创建按钮,其图像位于文本旁边,如下所示:
<corecontrols:IdyllicButton Name="btnClose" Height="30">
<StackPanel Orientation="Horizontal">
<Image Source="/MHA.Modules.PolicyAdmin;component/Images/Cancel.png"/>
<TextBlock VerticalAlignment="Center" Margin="5,0" Text="Close"/>
</StackPanel>
</corecontrols:IdyllicButton>
但是我无法将我的Image.ImageSource
设置为我在ResourceDictionary
中创建的StaticResource
,因为我遇到以下错误:
无法创建“System.Windows.Controls.Viewbox”类型的对象
应用于需要该类型的属性
“System.Windows.Media.ImageSource”
我也尝试过使用画布
有什么办法吗?希望这对某人有所帮助: 我找到了解决方案,而不是使用
图像
,而是在其位置使用矩形
控件,并将OpacityMask
设置为查看框
资源
<Rectangle Width="15" VerticalAlignment="Center"
Height="15"
Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform" Visual="{StaticResource Close}"/>
</Rectangle.OpacityMask>
</Rectangle>
我发现这个滚动的
MahApps.Metro
源代码用于WindowCommand
按钮。我认为没有必要直接在StackPanel中添加Viewbox。如果您想将其用作图像源,请单击导出按钮(Metro studio),它将询问格式和文件名,并将其另存为png。