Click here to Skip to main content
15,888,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Inside the method am getting the values in one local variable(when i click button method will run and get values in local variable).how do i bind the local variable values to datagrid

What I have tried:

ViewModel :

code is :
C#
local variable(UserDetails)

  private void Show()
        {
            //Users.AddRange(_context.Users);

           var UserDetails = (from a in _context.DocumentDatas
                               join b in _context.MetaDatas on a.DocId equals b.MId



                               select new
                               {
                                   a.Id,
                                   a.DocomentName,
                                   a.DocumentPath,
                                   b.Properties,
                                   b.Values



                               }).ToList();


Created one property

C#
private ObservableCollection<userdetails> _UserDetails;

        public ObservableCollection<userdetails> UserDetails
        {
            get { return _UserDetails; }
            set
            {
                _UserDetails = value;
                OnpropertyChanged("UserDetails");

            }
        }


XAML

and databinding :

HTML
<datagrid grid.row="5" grid.column="3" grid.columnspan="3" margin="20" horizontalalignment="Center" verticalalignment="Center" width="350" 
="" itemssource="{Binding UserDetails}" autogeneratecolumns="False">
            <datagrid.columns>
                <datagridtextcolumn header="Id" binding="{Binding Id,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                <datagridtextcolumn header="DocomentName" binding="{Binding DocomentName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                <datagridtextcolumn header="DocumentPath" binding="{Binding DocumentPath,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                <datagridtextcolumn header="Properties" binding="{Binding Properties,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                <datagridtextcolumn header="Values" binding="{Binding Values,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
Posted
Updated 18-Dec-19 20:42pm
v3
Comments
Richard Deeming 19-Dec-19 8:31am    
You don't bind to a local variable; you bind to a property.

Your need to populate your UserDetails property from your local variable. To do that, you will need to map the anonymous type from your local variable to your userdetails class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900