[英]WPF Control Image fails in WinForms
I am noob in WPF. 我是WPF的菜鸟。 I have a tab control with an icon on the tabs. 我有一个标签控件,标签上有一个图标。 When I import it by ElementHost the control in winforms, the icon does not appear on the tab. 当我通过ElementHost导入winforms中的控件时,图标不会出现在选项卡上。 I load the icon image from Resource. 我从Resource加载图标图像。
XAML Code: XAML代码:
<UserControl x:Class="WPF_Prueba.TabControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<ResourceDictionary>
<BitmapImage x:Key="tabIcon" UriSource="/Resources/delete.png" />
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<TabControl Name="tabDynamic" ItemsSource="{Binding}" SelectionChanged="tabDynamic_SelectionChanged">
<TabControl.Resources>
<DataTemplate x:Key="TabHeader" DataType="TabItem">
<DockPanel>
<Button Name="btnDelete" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" DockPanel.Dock="Right" Background="Transparent" Margin="5,0,-3,0" Padding="0" Click="btnDelete_Click" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=Name}">
<Image Source="{StaticResource tabIcon}" Height="10" Width="10"></Image>
</Button>
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=TabItem}, Path=Header}" />
</DockPanel>
</DataTemplate>
</TabControl.Resources>
</TabControl>
</Grid>
</UserControl>
If anyone can help me please. 如果有人可以帮助我。 Sorry for typos. 对不起打字错误。
Best regards. 最好的祝福。
Make sure your png
file has it's Build Action
set to Resource
: 确保你的png
文件的Build Action
设置为Resource
:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.