locked
Show image XML file RRS feed

  • Question

  • Hello people, 

    I develop a windows metro aplication in c# and I can not show image in gridview to a XML file. My images are in my project in folder images. I create a xml file with this :

    <?xml version="1.0" encoding="utf-8" ?>
    <images>
      <image>
        <imageUrl >images\ESTT2.jpg</imageUrl>
      </image>  
      <image>
        <imageUrl>images\ESGT2.jpg</imageUrl>
      </image> 
      <image>
        <imageUrl>images\ESGT2.jpg</imageUrl>
      </image> 
    </images>

    this file is in my folder Assets.

    In code behind:

     XDocument xmlDoc = XDocument.Load("Assets/data.xml");
                    IEnumerable<ShowImage> images = from item in xmlDoc.Descendants("image")
                                              select
                                              new ShowImage(item.Element("imageUrl").Value);
                                             
                    ListEscolas.ItemsSource=images;

    and this class:

     class ShowImage
        {
           
            public string imageUrl{set; get;}
    
    
    
            public ShowImage(string image)
                {
    
                    imageUrl = "ms-appx:///Assets/" + image; ;
                } 
        }

    my gridview 

     <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" >
            <!-- Mostra o Título-->
            <TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}" VerticalAlignment="Top" Margin="80,60,60,0" />
    
            <GridView Name="GridEscolas" 
                      IsRightTapEnabled="False"  
                      ItemsSource="{Binding}" 
                      AllowDrop="True"  
                      TabIndex="1"
                      ItemClick="Event_Page"
                      IsItemClickEnabled="True" 
                      Padding="116,136,116,46"
                      Grid.RowSpan="2"
                      SelectionMode="None"
                      IsSwipeEnabled="false"
                      AutomationProperties.AutomationId="ItemsGridView"
                      AutomationProperties.Name="Items"
                      VerticalAlignment="Center" 
                      
                      >
                <GridView.ItemTemplate>
    
                    <DataTemplate>
                        <Grid HorizontalAlignment="Left" Height="330" Width="330" VerticalAlignment="Top" Background="DarkGray" Margin="10">
                            <Image Margin="0" Source="{Binding imageUrl}" Stretch="Fill" Width="320" Height="320" x:Name="imagegrid" />
                            <Grid HorizontalAlignment="Left" Height="70" VerticalAlignment="Bottom" Width="330" Background="#E5231F20" >
                                <TextBlock HorizontalAlignment="Left" Foreground="White" TextWrapping="Wrap" Text="{Binding NomeEscola}" VerticalAlignment="Center" FontWeight="Bold" FontSize="18" Tag="{Binding procedureName}" Margin="0,0,0,0"  FontFamily="Verdana"/>
                            </Grid>
                        </Grid>
                    </DataTemplate>
    
                </GridView.ItemTemplate>
            </GridView>

    thanks for help me

     
    Thursday, October 10, 2013 5:26 PM

Answers

  • ok; its very simple, but easy to overlook.

    your xml:

    Assets/ESTT2.jpg

    in code:

    imageUrl =

    "ms-appx:///Assets/"+ image;

    result:

    "ms-appx:///Assets/assets/estt2.jpg";

    so make the code:

    imageUrl = "ms-appx:///" + image;

    and works


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by Aurelien Mota Thursday, October 10, 2013 9:54 PM
    Thursday, October 10, 2013 9:39 PM

All replies

  • try to change the \ in the xml to a /

    images\ESTT2.jpg => images/ESTT2.jpg

    and you sure the files are in the package (their build action is set content ?)


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Thursday, October 10, 2013 6:11 PM
  • yes the files is in packages, look this 

    Thursday, October 10, 2013 8:23 PM
  • also need to set the properties of the file, click the file in the solution explorer then press f4


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Thursday, October 10, 2013 8:53 PM
  • and what change? I have the same than image, 

    thanks

    Thursday, October 10, 2013 9:04 PM
  • build action have to be content. can you share a demo project that i can run so can see whats going wrong?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Thursday, October 10, 2013 9:06 PM
  • ok this is my demo, 

    https://skydrive.live.com/redir?resid=CDD47EAA4D89F4E7!292&authkey=!AHcMAZW5P7o-ESk

    thank you

    Thursday, October 10, 2013 9:23 PM
  • ok; its very simple, but easy to overlook.

    your xml:

    Assets/ESTT2.jpg

    in code:

    imageUrl =

    "ms-appx:///Assets/"+ image;

    result:

    "ms-appx:///Assets/assets/estt2.jpg";

    so make the code:

    imageUrl = "ms-appx:///" + image;

    and works


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by Aurelien Mota Thursday, October 10, 2013 9:54 PM
    Thursday, October 10, 2013 9:39 PM
  • thank you so much, it's work
    Thursday, October 10, 2013 9:55 PM