WPF 在运行时看不到图像
WPF Cannot see image in runtime
我已经为上下文菜单创建了 3 个图像。问题是我在运行时看不到它们。 (我可以在编辑器中看到它们window)
我已经
- 将编译类型更改为资源
图片类型为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>
好吧,我通过简单地将我加载到我的项目中的图像拖到 Source="<dragged image path>"
中解决了这个问题。它将插入图像的完整路径。
我已经为上下文菜单创建了 3 个图像。问题是我在运行时看不到它们。 (我可以在编辑器中看到它们window)
我已经
- 将编译类型更改为资源
图片类型为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>
好吧,我通过简单地将我加载到我的项目中的图像拖到 Source="<dragged image path>"
中解决了这个问题。它将插入图像的完整路径。