【问题标题】:WPF Images don't display when View is switched out关闭视图时不显示 WPF 图像
【发布时间】:2009-08-14 16:53:13
【问题描述】:

我有以下 WPF 应用程序

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication1"        
    Title="Window1" Height="300" Width="300">
    <Grid>
        <TabControl>
            <TabItem Header="Test1">
                <local:ImageView />
            </TabItem>
            <TabItem Header="Test2">
                <local:ImageView />
            </TabItem>
            <TabItem Header="Test3">
                <local:ImageView />
            </TabItem>
        </TabControl>
    </Grid>
</Window>

ImageView 是一个 UserControl 定义为

<UserControl x:Class="ImageView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Grid>
    <Image Source="pack://application:,,,/Resources/icon.png" Width="15" Height="15" />
    </Grid>
</UserControl>

当我在 TabItems 之间切换时,有时图像显示,有时不显示。为什么会这样?

【问题讨论】:

    标签: wpf image xaml user-controls


    【解决方案1】:

    为了记录,我能够通过将 ImageView 更改为来解决这个问题

    <UserControl x:Class="ImageView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Grid>
        <Grid.Resources>
            <BitmapImage x:Key="IconImageSource" UriSource="pack://application:,,,/Resources/icon.png" />
        </Grid.Resources>
    
        <Image Source="{StaticResource IconImageSource}" Width="15" Height="15" />
    </Grid>
    

    但我仍然很好奇为什么第一种方法不起作用

    【讨论】:

      猜你喜欢
      • 2016-03-13
      • 2012-05-18
      • 2017-09-11
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 2013-06-09
      • 1970-01-01
      • 2015-04-11
      相关资源
      最近更新 更多