locked
How do I return a collection as a return type using PageFunction? RRS feed

  • Question

  •  
    Hi,
     
    In my WPF application I need to return a collection as return type using a PageFunction. Is it possible? If yes how do I do it?
     
    Thanks & Regards,
    Deepak.
     
     
     
    Wednesday, January 14, 2009 1:55 PM

Answers

  • Hi Deepak,
        PageFunction is a Generic type, so you simply need to pick a return type and make the appropriate changes to the .xaml and .xaml.cs files involved.  Here's an example I just tried with ArrayList:

    PageFunction1.xaml Header:

    <PageFunction  
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:sys="clr-namespace:System.Collections;assembly=mscorlib"   
        x:Class="WindowPadding.PageFunction1" 
        x:TypeArguments="sys:ArrayList" 
        Title="PageFunction1"


    PageFunction1.xaml.cs changes:

        /// <summary>  
        /// Interaction logic for PageFunction1.xaml  
        /// </summary>  
        public partial class PageFunction1 : PageFunction<ArrayList>  
        {  
            public PageFunction1()  
            {  
                InitializeComponent();  
            } 

    Return Event Args Changes:

                ReturnEventArgs<ArrayList> args = new ReturnEventArgs<ArrayList>(someArrayList);  
                OnReturn(args);  
     

    Beyond that, there's nothing stopping you from using practically any type as your return type for a PageFunction.

    Hope this helps,
    Matt
    SDET : Deployment/Hosting
    • Marked as answer by Tao Liang Monday, January 19, 2009 5:59 AM
    Friday, January 16, 2009 6:55 PM
  • <PageFunction 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:local="clr-namespace:WPFTest" 
        x:Class="WPFTest.PageFunctionTest" 
        x:TypeArguments="local:MyList" 
        Title="PageFunctionTest"
    </PageFunction> 


    using System.Collections.Generic; 
    using System.Windows.Navigation; 
     
    namespace WPFTest 
        /// <summary> 
        /// Interaction logic for PageFunctionTest.xaml 
        /// </summary> 
        public partial class PageFunctionTest : PageFunction<MyList> 
        { 
            public PageFunctionTest() 
            { 
                InitializeComponent(); 
                Return += (sender, e) => { e.Result = new MyList { "string 1""string 2"}; }; 
            } 
        } 
     
        public class MyList : List<string
        {} 
     


    Bigsby, Lisboa, Portugal
    • Marked as answer by Tao Liang Monday, January 19, 2009 5:59 AM
    Friday, January 16, 2009 7:31 PM

All replies

  • Hi Deepak,
        PageFunction is a Generic type, so you simply need to pick a return type and make the appropriate changes to the .xaml and .xaml.cs files involved.  Here's an example I just tried with ArrayList:

    PageFunction1.xaml Header:

    <PageFunction  
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:sys="clr-namespace:System.Collections;assembly=mscorlib"   
        x:Class="WindowPadding.PageFunction1" 
        x:TypeArguments="sys:ArrayList" 
        Title="PageFunction1"


    PageFunction1.xaml.cs changes:

        /// <summary>  
        /// Interaction logic for PageFunction1.xaml  
        /// </summary>  
        public partial class PageFunction1 : PageFunction<ArrayList>  
        {  
            public PageFunction1()  
            {  
                InitializeComponent();  
            } 

    Return Event Args Changes:

                ReturnEventArgs<ArrayList> args = new ReturnEventArgs<ArrayList>(someArrayList);  
                OnReturn(args);  
     

    Beyond that, there's nothing stopping you from using practically any type as your return type for a PageFunction.

    Hope this helps,
    Matt
    SDET : Deployment/Hosting
    • Marked as answer by Tao Liang Monday, January 19, 2009 5:59 AM
    Friday, January 16, 2009 6:55 PM
  • <PageFunction 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:local="clr-namespace:WPFTest" 
        x:Class="WPFTest.PageFunctionTest" 
        x:TypeArguments="local:MyList" 
        Title="PageFunctionTest"
    </PageFunction> 


    using System.Collections.Generic; 
    using System.Windows.Navigation; 
     
    namespace WPFTest 
        /// <summary> 
        /// Interaction logic for PageFunctionTest.xaml 
        /// </summary> 
        public partial class PageFunctionTest : PageFunction<MyList> 
        { 
            public PageFunctionTest() 
            { 
                InitializeComponent(); 
                Return += (sender, e) => { e.Result = new MyList { "string 1""string 2"}; }; 
            } 
        } 
     
        public class MyList : List<string
        {} 
     


    Bigsby, Lisboa, Portugal
    • Marked as answer by Tao Liang Monday, January 19, 2009 5:59 AM
    Friday, January 16, 2009 7:31 PM