私は Windows Phone 8 用のアプリの開発を開始し、最初のステップを実行しようとしています (私は既に WinForms の C# のバックグラウンドを持っています)。しかし、すべて、特に XAML が非常に複雑に見えることに気付きました。リストの作成などの最も単純なことでさえ、*はとても面倒です。フラットで非常に単純なバインド (ほとんどのチュートリアルで提案されているように) で機能しますが、それは硬くて柔軟性がありません。
これらの情報を含む項目 (「o」は各項目) を含むリスト (LongListSelector) を生成したい:
<o.Name>
<o.TotalAmount> (<o.Things.Count>)
[if o.MiscThings.Count > 0]<o.MiscThings.Count> other thing(s)[/if]
データ例:
John Doe
22.97 (3)
2 other thing(s)
Jane Doe
7.55 (1)
私はこれを達成しようとしました:
<phone:LongListSelector x:Name="LLS_Summary">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBlock Text="{Binding TotalAmount} ({Binding Things.Count})" /> <!-- throws an error, concatenation doesn't work? -->
<!-- well yeah this is obviously not possible with data binding -->
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
// in .cs
LLS_Summary.ItemsSource = App.MyItems; // IList
程遠い。連結は、事前にある種のコンバーターがあり、条件付きのものがこのようにまったく機能しない場合にのみ機能するようです。
したがって、私のアプローチは、実行時に要素を自分で生成することです。しかし、どのように?LongListSelector コントロールは、これをまったくサポートしていないようです。WinForms では、次のようにします。
Label line1 = new Label();
line1.Text = o.Name;
Label line2 = new Label();
line2.Text = o.TotalAmount + " (" + o.Things.Count + ")";
Label line3 = new Label();
if (o.MiscThings.Count > 0)
line3.Text = o.MiscThings.Count + " other thing(s)";
else
line3.Text = "";
// sizing, positioning etc.
Panel panel = new Panel();
panel.Controls.Add(line1);
panel.Controls.Add(line2);
panel.Controls.Add(line3);
LLS_Summary.Controls.Add(panel);
Win(P)RT でこれをどのように達成できますか? これはそれを行う方法でもありますか?