我知道这是一个简单的问题,但我找不到任何可以帮助我解决问题的答案。 有人可以告诉我为什么我可以在设计器中看到图标,但不能在运行时看到?包含菜单项的XAML如下所示。我确实尝试将图标/图像添加到App.xaml中的Application.Resources,正如您在第一个菜单项中看到的那样,但仍然无法正常工作...请参阅下面的App.xaml中的标记。
<Menu Margin="0,0,135,0">
<MenuItem x:Name="DownLoadReportMi" Header="_File" Click="DownLoadReportMI_Click" HorizontalAlignment="Left" VerticalAlignment="Top" >
<MenuItem Header="_DownLoad Report..." Icon="{DynamicResource DownLoadIcon}"/> <!--Icon="{DynamicResource DownLoadIcon}"-->
<Separator />
<MenuItem Header="_Request Report...">
<MenuItem.Icon>
<Image Source="UpLoadIcon.png" Height="24" Width="24" x:Name="UpLoadIcon" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</MenuItem.Icon>
</MenuItem>
<Separator/>
<MenuItem x:Name="ExitMi" Header="_Exit..." Click="ExitMenuItem_Click" >
<MenuItem.Icon>
<Image Source="ExitIcon.png" Height="24" Width="24" x:Name="ExitIcon" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
<MenuItem Header="Help">
<MenuItem Header="_About...">
<MenuItem.Icon>
<Image Source="HelpIcon.png" Height="24" Width="24" x:Name="HelpIcon" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
App.xaml中:
<Application.Resources>
<ResourceDictionary>
<Image x:Key="DownLoadIcon" Source="DownLoadIcon.png"/>
<Style TargetType="MenuItem" x:Key="GredientBg">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,1" EndPoint="2,0">
<GradientStop Offset="0.142" Color="WhiteSmoke"/>
<GradientStop Offset="0.5" Color="#FF176393"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Application.Resources>