How update List of datagrid c# wpf caliburn.micro -


in class :

 [export(typeof(iscreen))]     public class bolleviewmodel : screen     {               ....     } 

i have list :

public list<article> list { get; private set; } 

this list binding of datagrid list :

<datagrid horizontalalignment="stretch" selecteditem="{binding selectedarticle}"             margin="14,41,12,61" verticalalignment="stretch" autogeneratecolumns="false" x:name="list"> 

i want when call method update , updates values ​​of list , datagrid. update method:

    public void update(list<article> list)     {         list = list;         notifyofpropertychange("list");     } 

what wrong ? ?

caliburn.micro doesn't support convention based binding datagrid out of box, can see checking conventionmanager static constructor.

you can write own convention using conventionmanager, or can set itemssource property binding instead in view.

e.g.

<datagrid itemssource="{binding articles}" selecteditem="{binding selectedarticle}"         margin="14,41,12,61" autogeneratecolumns="false"         horizontalalignment="stretch" verticalalignment="stretch"> ... 

other points:

  1. list isn't property name list of articles
  2. caliburn.micro provides lambda based override notifyofpropertychange should use catch refactorings
  3. a better pattern implementing inpc property following (this because it's no longer responsibility of consumer changes property invoke propertychanged event)

use:

private list<article> articles;  public list<article> articles  {         {        return this.articles;    }     private set    {        if (this.articles == value)        {            return;        }          this.articles = value;        this.notifyofpropertychange(() => this.articles);    } } 

as collection type, should ensure return collection rather null. prevents need consumers check avoid null reference exceptions.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -