Wednesday, 15 July 2015

C# WPF - Write to Listview from any class -



C# WPF - Write to Listview from any class -

i have ui in mainwindow.xaml , in window have listview i'd utilize logging.

how write listview class without having pass window object whole way through system?

i've tried making method in mainwindow code behind called log(string) , accessing class mainwindow.log("some text") no joy!

perhaps i'm not exclusively grasping whole object oriented part of problem :(

help much appreciated!

cheers, dave

you using wpf ! not utilize ui command type instances within end language. utilize data-binding, wpf tailored to, bind list view instance of end class. , pass around of back-end instance of class .

the concrete basic implementation not suitable contest, basic thought may

class log { ..... list<string> logdata; public list<string> logdata { //property bound list view ui { homecoming logdata; } } public void addlog(string s) { logdata.add(s); notifypropertychanged(.. logdata ..); } }

after in shared space of code created log log. execute addlog, add together string lost of log, , raise event update ui.

for info binding examples may on:

a simple illustration of info binding in wpf

data binding overview

or google simpler or more suitable examples you.

c# wpf xaml listview

No comments:

Post a Comment