WPF控件图像在WinForms中失败 [英] WPF Control Image fails in WinForms

查看:120
本文介绍了WPF控件图像在WinForms中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WPF的菜鸟。我有一个标签控件,标签上有一个图标。当我通过ElementHost导入winforms中的控件时,图标不会出现在选项卡上。我从资源中加载图标图片。

I am noob in 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. I load the icon image from Resource.

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.

祝你好运。

推荐答案

确保你的 png 文件有构建操作设置为资源

Make sure your png file has it's Build Action set to Resource:

这篇关于WPF控件图像在WinForms中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆