WPF无法在运行时看到图像(WPF Cannot see image in runtime)

编程入门 行业动态 更新时间:2024-10-24 16:22:42
WPF无法在运行时看到图像(WPF Cannot see image in runtime)

我为我的上下文菜单创建了3个图像。 问题是我无法在运行时看到它们。 (我可以在编辑器窗口中看到它们)

我已经

将编译类型更改为资源

和图像类型为png(以防万一)

<Color x:Key="BackgroundColor" A="255" R="19" G="19" B="19"/> <BitmapImage x:Key="BiCut" UriSource="Images/cut.tif"/> <BitmapImage x:Key="BiCopy" UriSource="Images/copy.tif"/> <BitmapImage x:Key="BiPaste" UriSource="Images/paste.tif"/> <SolidColorBrush x:Key="BorderBrush" Color="#ECECEC"/> <Style TargetType="ContextMenu"> <Setter Property="Foreground" Value="{StaticResource BorderBrush}"/> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="Grid.IsSharedSizeScope" Value="true" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ContextMenu"> <Border BorderThickness="1" BorderBrush="#2468d9" Padding="2" Background="#131313"> <StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal" Height="20"> <Image Source="{StaticResource BiCut}" Width="20"/> <Button Content="Ausschneiden" Margin="5,0,0,0"/> <TextBlock Text="Strg+X" TextAlignment="Center" VerticalAlignment="Center" Margin="5,0,0,0"/> </StackPanel> </StackPanel> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>

I've created 3 Images for my context menu. The problem is that I can not see them in runtime. (I can see them in the editor window)

I've already

changed compile type to resource

and image type to png (just in case)

<Color x:Key="BackgroundColor" A="255" R="19" G="19" B="19"/> <BitmapImage x:Key="BiCut" UriSource="Images/cut.tif"/> <BitmapImage x:Key="BiCopy" UriSource="Images/copy.tif"/> <BitmapImage x:Key="BiPaste" UriSource="Images/paste.tif"/> <SolidColorBrush x:Key="BorderBrush" Color="#ECECEC"/> <Style TargetType="ContextMenu"> <Setter Property="Foreground" Value="{StaticResource BorderBrush}"/> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="Grid.IsSharedSizeScope" Value="true" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ContextMenu"> <Border BorderThickness="1" BorderBrush="#2468d9" Padding="2" Background="#131313"> <StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal" Height="20"> <Image Source="{StaticResource BiCut}" Width="20"/> <Button Content="Ausschneiden" Margin="5,0,0,0"/> <TextBlock Text="Strg+X" TextAlignment="Center" VerticalAlignment="Center" Margin="5,0,0,0"/> </StackPanel> </StackPanel> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>

最满意答案

好吧,我只需将我加载到项目中的图像拖动到Source="<dragged image path>" 。 它将插入图像的完整路径。

Okay well I solved it by simply drag the image, which I loaded into my project, into Source="<dragged image path>". It will insert the full path of the image.

更多推荐

Key,Images,BorderBrush,电脑培训,计算机培训,IT培训"/> <meta name="descri

本文发布于:2023-08-03 16:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393605.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   WPF   runtime   image

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!