0

我想在单击按钮时一个一个地添加 Listpickers,同时向下到 Listpickers 的控件应该在每次添加 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;
    }
}
}
4

2 回答 2

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);
于 2012-08-21T14:36:08.187 回答
0

您可以创建 ListPicker 并使用绑定到 ObservableCollection。

ObsarvableCollection 的优点是您的更改会在视图上自动更新。有关详细信息,请参阅:MSDN。也看看stackoverflow.com/questions/9745279

于 2012-08-21T14:04:13.880 回答