locked
how to pass parameter from xaml to viewmodel in wpf RRS feed

  • Question

  • Hai 

         I am trying to pass parameter from Xaml to ViewModel

    I use code below

    Xaml

        xmlns:Local1="clr-namespace:BillingPurchase"
    
    <Page.Resources>
            <ObjectDataProvider  x:Key="BillingVM" ObjectType="{x:Type Local1:BillingVM}">
                    <ObjectDataProvider.ConstructorParameters>
                    <sys:String>Purchase</sys:String>
                    </ObjectDataProvider.ConstructorParameters>
    </Page.Resources>
     <Grid DataContext="{StaticResource BillingVM}">
    
     </Grid>
    
    

    in ViewModel

     public string BillType { get; set; }
    
     public BillingVM(string ty)
        {
                BillType = ty;
        }
    I use 2 ui according to this parameter When I run this code I get parameter passed in BillType

    But My ui is not loading it shows 'Object reference not set to an instance of an object.' Error in

       InitializeComponent();

    Please help me what is the problem.

    Thanks.



     

     


    programmer


    Monday, April 20, 2020 5:15 PM

All replies

  • https://docs.microsoft.com/answers/topics/wpf.html

    New location of WPF forum...

    Monday, April 20, 2020 8:40 PM