Précédent   Forum du club des développeurs et IT Pro > Dotnet > Développement Windows > WinRT
WinRT Forum d'entraide sur le développement d'applications Metro pour Windows 8 avec WinRT
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 03/11/2012, 23h45   #1
wapiti89
Nouveau Membre du Club
 
Inscription : janvier 2011
Messages : 91
Détails du profil
Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2011
Messages : 91
Points : 35
Points : 35
Par défaut GridView, Binding et frame

Bonjour à tous,

Je tente de m'initier à la programmation WinRT en réalisant une application assez simple, mais qui déjà me pose problème...

Le premier problème vient lorsque je tente de faire un binding d'un gridView. J'ai définit dans ma MainPage.xaml une frame :

Code :
<Frame Margin="0,0,40,40" Grid.Row="2" Grid.Column="1" x:Name="frame" />
Via un clic sur des textBlock, l'affichage de la frame est censé changer.

Par défaut, je souhaite afficher dans ma frame, le contenu de la page Page1.xaml. Dans ma MainPage.xaml.cs, voici donc le code que je fais et qui semble marcher :

Code :
1
2
3
4
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    frame.Navigate(typeof(Page1));
}
Dans la Page1, je tente de binder un gridView. Voici alors le contenu du fichier Page1.xaml :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<common:LayoutAwarePage
    x:Class="Projet.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Projet"
    xmlns:common="using:Projet.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
 
    <GridView x:Name="Page1GridView" ItemsSource="{Binding Page1List}" ItemTemplate="{StaticResource Page1ItemTemplate}"
            Grid.Row="1" Grid.Column="1" SelectionMode="Single" IsItemClickEnabled="True" />
 
</common:LayoutAwarePage>
Le template est quant à lui défini dans le fichier App.xaml :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<DataTemplate x:Key="Page1ItemTemplate">
                <StackPanel Orientation="Vertical">
                    <Image Source="{Binding Fond}" Width="200" Stretch="UniformToFill" Height="220" />
                    <Grid Height="40" Margin="0,-40,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Border Grid.Column="1">
                            <Border.Background>
                                <SolidColorBrush Color="Black" Opacity="0.7" />
                            </Border.Background>
                            <TextBlock Text="{Binding Nom}" FontWeight="Light" VerticalAlignment="Center" FontSize="28" Margin="10,0,10,0" />
                        </Border>
                    </Grid>
                </StackPanel>
            </DataTemplate>
Pour binder, voici ce que je fais dans mon fichier Page1.xaml.cs :

Code :
DefaultViewModel["Page1List"] = DPage1List.GetPage1List();
La méthode statique DPage1List.GetPage1List() me renvoie une List d'objet ayant 2 propriétés : "Nom" et "Fond".

Le problème est que rien ne se passe, le binding ne semble pas se faire. Pourtant, la liste renvoyée n'est pas vide.

Que manque-t-il à mon binding pour qu'il puisse se faire ?

Merci d'avance pour votre aide !
wapiti89 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/11/2012, 14h27   #2
wapiti89
Nouveau Membre du Club
 
Inscription : janvier 2011
Messages : 91
Détails du profil
Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2011
Messages : 91
Points : 35
Points : 35
J'ai finalement réussi à binder en passant par le code C# et non le code XAML
wapiti89 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 04h32.


 
 
 
 
Partenaires

Hébergement Web