locked
Why isn't my code working?

    Question

  • Below is my code in XAML. It is not functioning right and everytime I run it, it only shows the names and not the pictures. Why is this so? Please reply back quickly!

    <Page
        x:Class="MyFirstApp.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MyFirstApp"
        xmlns:d="http://schemas.m icrosoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">

        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <!-- Back button and page title -->
            <Grid Grid.Row="0" Grid.Column="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="120"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBlock x:Name="pageTitle"  Grid.Column="1" Text=" My First Windows 8 App" Style="{StaticResource PageHeaderTextStyle}"/>
            </Grid>

            <GridView Grid.Row="1" Grid.Column="0" x:Name="list" Margin="116,0,0,46">
                <GridView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Image Source="{Binding Photo}" Width="200" Height="130" Stretch="UniformToFill" />
                            <Border Background="#A5000000" Height="45" VerticalAlignment="Bottom">
                                <StackPanel Margin="10,-2,-2,-2">
                                    <TextBlock Text="{Binding FullName}" Margin="0,20,0,0"  Foreground="#7CFFFFFF" HorizontalAlignment="Left"  />
                                </StackPanel>
                            </Border>
                        </Grid>
                    </DataTemplate>
                </GridView.ItemTemplate>
            </GridView>
        </Grid>
    </Page>

    Saturday, January 04, 2014 3:35 AM

All replies

  • how the Photo property looks on your model?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Saturday, January 04, 2014 2:42 PM
  • Do you mean the XAML code?

    If so, here it is: 

    <Page
        x:Class="MyFirstApp.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MyFirstApp"
        xmlns:d="http://schemas.m icrosoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">

        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <!-- Back button and page title -->
            <Grid Grid.Row="0" Grid.Column="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="120"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBlock x:Name="pageTitle"  Grid.Column="1" Text=" My First Windows 8 App" Style="{StaticResource PageHeaderTextStyle}"/>
            </Grid>

            <GridView Grid.Row="1" Grid.Column="0" x:Name="list" Margin="116,0,0,46">
                <GridView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Image Source="{Binding Photo}" Width="200" Height="130" Stretch="UniformToFill" />
                            <Border Background="#A5000000" Height="45" VerticalAlignment="Bottom">
                                <StackPanel Margin="10,-2,-2,-2">
                                    <TextBlock Text="{Binding FullName}" Margin="0,20,0,0"  Foreground="#7CFFFFFF" HorizontalAlignment="Left"  />
                                </StackPanel>
                            </Border>
                        </Grid>
                    </DataTemplate>
                </GridView.ItemTemplate>
            </GridView>
        </Grid>
    </Page>

    Thursday, January 09, 2014 11:33 PM
  • Hi incipio,

    I think Dave means you set your Image control source by binding Photo, so what you have done with Photo, in other words, where did you set the image control's context?

    Before you could bind a property of a object, you need set the object as its context firstly.

    Of course, if you want to resolve it simply, you could turn out it in code.

    mi = ref new Myimage();
    	Windows::Foundation::Uri^ ur = ref new Windows::Foundation::Uri(L"ms-appx:///Assets/StoreLogo.scale-100.png");
    	BitmapImage^ bi = ref new BitmapImage(ur);
    	mi->Photo = bi;
    	mi->myPhoto = bi;
    	myimage->Source = mi->myPhoto;// the image control

    You also could do this on the set accessor of the object to update the image control.

    Regards!

    Xiaoliang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, January 15, 2014 1:52 AM
    Moderator