0

I have 2 UserControl pages. In one I have a ListBox and a "continue" Button. I want to pass the list to another UserControl page after I click "continue" but i can't figure out how to do it (Just found examples for Form or Window).

I already found how to move to another page, but not how to pass the data in it. Thanks!

This is my code: The button in the first Xaml (I have there a ListBox named lbOne):

<Button x:Name="button" 
        Content="Continue"  
        Grid.Column="2"  
        Margin="81,0,0,-30"  
        RenderTransformOrigin="0.184,-1.455" 
        Height="30" VerticalAlignment="Bottom"
        Style="{DynamicResource BaseButtonStyle2}"
        Click="button_Click"
        Command="NavigationCommands.GoToPage" 
        CommandParameter="/Pages/NextPage/nextPage.xaml"/>

And this is the list:

ObservableCollection<My_Data> list = new ObservableCollection<My_Data>();
public Home()
{
    InitializeComponent();
    list.Add(new My_Data("first", "explanation"));
    list.Add(new My_Data("second", "explanation"));
    list.Add(new My_Data("third", "explanation"));
    list.Add(new My_Data("forth", "explanation"));
    list.Add(new My_Data("fifth", "explanation"));

    lbOne.ItemsSource = list;
}

Edit: I will just be clear and say i want to share the data in the ListBox and not the ObservableCollection because i add more data to the listbox itself at the entire code (This way: lbOne.Items.Insert(insertAtIndex, dragDropData);)

Ben
  • 201
  • 1
  • 4
  • 13
  • 8
    The UserControls should bind to a shared view model in their DataContext. Search the web for the MVVM architecture pattern and the basics of WPF data binding. – Clemens Dec 19 '17 at 13:13
  • I will try to find something about it, thanks. – Ben Dec 20 '17 at 08:28
  • It is always good to use Patterns like MVVM , but if you want other solutions Link1 : https://wpfglue.wordpress.com/tag/gotopage/ Link2: http://www.actiprosoftware.com/community/thread/3496/ribbon-tab-that-supports-icheckablecommandpar – Jophy job Dec 21 '17 at 12:33

0 Answers0