how to pass parameter from xaml to viewmodel in wpf

  • Thread starter Thread starter babucr
  • Start date Start date
B

babucr

Guest
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

Continue reading...
 
Back
Top