2012-03-25 29 views
1

Windows Phone 7アプリケーションで作業していますが、通常は他のWPF/WinFormアプリケーションで問題が発生していますが、このコードはWphone 7で問題なく動作します。データクラス:リストボックスの項目が表示されない

public class AlarmTemplate 
{ 
    public string Name { get; set; } 
    public string Time { get; set; } 
    public BitmapImage Activated { get; set; } 

    public AlarmTemplate(string name, string time, string activated) 
    { 
     Name = name; 
     Time = time; 
     Activated = new BitmapImage 
         {UriSource = new Uri("Images/alarm_" + activated + ".png", UriKind.RelativeOrAbsolute)}; 
    } 

} 
読みお父さんは、また、私はハードコード化データとその動作していないと試みた

次のもの:ここで

private List<AlarmTemplate> _templateList = new List<AlarmTemplate>(); 

private void PopulateList() 
    { 
     using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      if (!storage.FileExists("file.txt")) 
       return; 

      using (var reader = new BinaryReader(storage.OpenFile("file.txt", FileMode.Open))) 
      { 
       var s = reader.ReadInt32(); 
       for (var i = 0; i < s; i++) 
       { 
        _templateList.Add(new AlarmTemplate(reader.ReadString(), reader.ReadString(), 
                 reader.ReadString())); 
       } 
      } 
     } 
     lbAlarms.ItemsSource = _templateList; 
} 

があるXAML:

<ListBox Height="176.135" HorizontalAlignment="Left" Margin="0,567.164,0,0" Name="lbAlarms" VerticalAlignment="Top" Width="456" Foreground="#FFFFC7C7" ItemsSource="{Binding}" Background="Transparent" AllowDrop="False" BorderThickness="1" BorderBrush="#00900707" Grid.Row="1" Hold="lbAlarms_Hold"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel Grid.Row="1" Height="52" Orientation="Horizontal" Name="spList" VerticalAlignment="Top" Width="480" Margin="0,329,0,0" UseLayoutRounding="False"> 
        <Image Height="52" Name="imTStatus" Stretch="Uniform" Width="73" Margin="10,0,0,0" UseLayoutRounding="False" Source="{Binding Activated}" /> 
        <StackPanel Height="52" Name="spHolder" Width="300" Margin="10,0,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Left" UseLayoutRounding="False"> 
         <TextBlock Height="26" Name="tbTTime" Text="{Binding Time}" Foreground="Black" FontFamily=".\Fonts\Nokia.ttf#Nokia" TextAlignment="Left" FontWeight="Bold" Width="230" FontSize="24" HorizontalAlignment="Left" UseLayoutRounding="False" /> 
         <TextBlock Height="26" Name="tbTName" Text="{Binding Name}" Foreground="Black" FontFamily=".\Fonts\Nokia.ttf#Nokia" HorizontalAlignment="Left" Width="297" /> 
        </StackPanel> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
+0

'List'の代わりに' ObservableCollection'を使ってみましたか?私はこれがデータバインディングに関してWPFとSilverlightとの間に顕著な違いがあることを発見しました。 – Bernard

+0

'_templateList'に実際に項目が含まれている場合は、別の場所での問題よりも、違いはありません。 –

+0

別のコードを表示してください。 – Ku6opr

答えて

2

あなたのコードが動作しています(私はスクロールバーが右側にあることに気付きましたが)あなたのテキストの色は黒で黒く、あまり目に見えません。

は、あなたがいることを変更したい場合がありますので、あなたのマージンは、あなたのリストボックスは、ページの下部に1つの未満のアイテム高い非常に小さいことを意味する、のTextBlock色Foreground="Black" :)

注意を取り除きます同じように。

+0

母さん、ありがとうございました。それは問題ではありませんでしたが、近くでは、 "StackPanel"は、スクロールする必要がありませんでしたので、上から200またはスムースでマージンを持っていました。仕事は今素晴らしいです:)、ありがとうございます –

0
private List<AlarmTemplate> _templateList = new List<AlarmTemplate>(); 
public List<AlarmTemplate> TemplateList 
{ 
    get { return _templateList; } 
    set { _templateList = value; } 
} 

に設定し、バインディングをTemplateListに設定します。

+0

例は実際にリストのバインディングを使用していないので、適切な改善ですが、この場合は違いはありません。既存のコードは実際にはそのまま動作しますが、項目はレイアウトの問題によって隠されています。 –

関連する問題