Question

I created public class "cBank". This class have

public string Name { get; set; }
public double first_session_in { get; set; }
public double second_session_in { get; set; }
public double third_session_in { get; set; }
public double first_session_out { get; set; }
public double second_session_out { get; set; }
public double third_session_out { get; set; }

I created list of obj in ManiPage constructor

List<cBank> oListBanks = new List<cBank>();
oListBanks.Add(new cBank {Name="Alior Bank", first_session_in = ...});
oListBanks.Add(new cBank {Name="Bank BPH",first_session_in=...});
this.ListPicker.ItemsSource = oListBanks;

I have in my xaml code:

<phone:PhoneApplicationPage.Resources>
  <DataTemplate x:Name="lpkBank">
    <TextBlock Text="{Binding Name}" />
   </DataTemplate>
</phone:PhoneApplicationPage.Resources>

I want to show only Name (of bank). rest xaml code:

<toolkit:ListPicker Header="Bank:" FullModeItemTemplate="{Binding lpkFullBank}"
                    ItemTemplate="{Binding lpkBank}" x:Name="ListPicker" 
                    Margin="12,15,12,0" Height="110" VerticalAlignment="Top" />

Now it shows only a name of classes in list picker. What should I do ?

Était-ce utile?

La solution 2

I solved it. I saw my mistake. Height="110" This was one of the reason why list didn't dropdown. The class is correct.

Constructor should look like this:

List<cBank> oListBanks = new List<cBank>();
oListBanks.Add(new cBank {Name="Alior Bank", first_session_in = ...});
oListBanks.Add(new cBank {Name="Bank BPH",first_session_in=...});
...
this.ListPicker.ItemsSource = oListBanks;

And XAML code should be:

<toolkit:ListPicker x:Name="ListPicker" Header="Bank:" > 
              <toolkit:ListPicker.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Name}" FontSize="30" HorizontalAlignment="Center"/>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.ItemTemplate>
            <toolkit:ListPicker.FullModeItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Name}" Width="150"/>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.FullModeItemTemplate>
        </toolkit:ListPicker>

Now all works properly.

Autres conseils

If you want to display from your ListPicker you can aslo use like this In the constructor:

List<cBank> oListBanks = new List<cBank>();
oListBanks.Add(new cBank {Name="Alior Bank", first_session_in = ...
oListBanks.Add(new cBank {Name="Bank BPH",first_session_in=...

and in your XAML code:

 <phone:PhoneApplicationPage.Resources>
    <toolkit:ListPicker x:Key="ListPicker" ItemsSource="{Binding oListBanks , ElementName=this}" SelectionMode="Single">
     <toolkit:ListPicker.ItemTemplate>
      <DataTemplate>
       <TextBlock Text="{Binding Name}" />
      </DataTemplate>
     </toolkit:ListPicker.ItemTemplate>
    </toolkit:ListPicker>
 </phone:PhoneApplicationPage.Resources>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top