我想在点击一个按钮的同时逐一添加Listpickers,同时对Listpickers的控件应该在listpicker的每个添加中向下移动。请给我一个想法。
用于创建listpicker的XAML代码。
<toolkit:ListPicker Grid.Row="0" Margin="5,76,226,-52" x:Name="list" ItemTemplate="{StaticResource PickerItemTemplate}" ItemCountThreshold="3"
FullModeItemTemplate="{StaticResource PickerFullModeItemTemplate}" FullModeHeader="Select your Monthly Debts:" SelectedIndex="2" CacheMode="BitmapCache"
FontFamily="Arial Black" FontSize="32" FontWeight="ExtraBlack"/>
C#代码:
List<payment> source = new List<payment>();
source.Add(new payment() { Name = "Car Payment" });
source.Add(new payment() { Name = "Credit UnionLoan" });
source.Add(new payment() { Name = "Spousal Support" });
source.Add(new payment() { Name = "Child Support" });
source.Add(new payment() { Name = "Visa" });
source.Add(new payment() { Name = "MasterCard" });
this.list.ItemsSource = source;
付款类文件:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace NewUIChanges
{
public class payment
{
public string Name
{
get;
set;
}
}
}
答案 0 :(得分:1)
您可以像任何其他控件一样动态地将ListPickers添加到UI。
对于您向下移动其他控件的其他要求,我建议您对上面显示的ListPicker XAML代码进行一些小改动。
<StackPanel x:Name="StackPanelListPickers" Grid.Row="0">
<toolkit:ListPicker Margin="5,76,226,-52" x:Name="list" ItemTemplate="{StaticResource PickerItemTemplate}" ItemCountThreshold="3"
FullModeItemTemplate="{StaticResource PickerFullModeItemTemplate}" FullModeHeader="Select your Monthly Debts:" SelectedIndex="2" CacheMode="BitmapCache"
FontFamily="Arial Black" FontSize="32" FontWeight="ExtraBlack"/>
</StackPanel>
然后在您要添加ListPickers的代码后面执行以下操作:
//Generate a dynamic listpicker
ListPicker lp = new ListPicker() { Name = "List2" };
lp.Template = this.Resources["PickerItemTemplate"] as ControlTemplate;
lp.FullModeItemTemplate = this.Resources["FullModeItemTemplate"] as DataTemplate;
//And all other properties of "lp" as you need ..I am not writing all here
//Now add this new Listpicker to the stackpanel which is the child of the Grid
this.StackPanelListPickers.Children.Add(lp);
答案 1 :(得分:0)
您可以创建ListPicker并使用绑定到ObservableCollection。
ObsarvableCollection的优点是您的更改会在视图上自动更新。 有关更多信息,请参阅:MSDN。 另请查看stackoverflow.com/questions/9745279