Reputation: 397
I want to add Listpickers one by one on clicking a button meanwhile the controls down to the Listpickers should move downwords on each addtion of listpicker.Suggest me an idea plz.
XAML code for creating listpicker.
<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# code:
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;
Payment class file:
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;
}
}
}
Upvotes: 0
Views: 688
Reputation: 5557
You can add ListPickers dynamically to the UI just like any other control.
And for your other requirement of moving other controls downwards, I would suggest you to make a small change to your ListPicker XAML code you showed above.
<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>
and then in the code behind where you want to add the ListPickers do the following:
//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);
Upvotes: 1
Reputation: 1709
You can create your ListPicker and use the binding to an ObservableCollection.
The advantage of the ObsarvableCollection is that your change are automaticly updated on the view. See : MSDN for more informations. Also have a look at stackoverflow.com/questions/9745279
Upvotes: 0