2009-08-14 4 views
0

je l'application WPF suivanteWPF Les images n'affichent pas quand la visibilité est mis hors

<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 est un UserControl défini comme

<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> 

Lorsque je passe entre TabItems, parfois l'affichage d'images , parfois non. Pourquoi cela arrive-t-il?

Répondre

0

Pour mémoire, j'ai pu contourner ce problème en changeant mon 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> 

Mais je suis toujours curieux de savoir pourquoi la première approche ne fonctionne pas

Questions connexes