c# - Binding TextBlock to a log file in WPF application -
i have wpf application output log log file. log file being written to. want display contents of log file textblock
on ui
<textblock style="{staticresource logviewstyle}" text="{binding logmessage,relativesource={relativesource mode=findancestor,ancestortype=window}}" x:name="logview" foreground="white" fontfamily="consolas" rendertransformorigin="0.415,0.382" grid.columnspan="2" margin="10,172,10,0"/>
the code shown below. somehow textblock not getting updated. doing wrong?
public partial class mainwindow : window, inotifypropertychanged { static string configfile = "si_config.yaml"; static string logfilepath = "c:\\si_data\\logs\\"; notifyicon nicon = new notifyicon(); public mainwindow() { initializecomponent(); myv v = configfilemanager.createtvfromconfigfile(configfile, logfilepath); list<myv> fv = configfilemanager.createfvfromconfigfile(configfile, logfilepath); readfile(logfilepath + "ms_interface.log"); fvdatabinding.itemssource = fightervehicles; } private string _filetext; public string filetext { { return _filetext; } set { if (string.equals(value, _filetext)) return; _filetext = value; onpropertychanged("filetext"); } } public void readfile(string path) { filetext = file.readalltext(path); onpropertychanged("filetext"); } //inotifypropertychanged members public event propertychangedeventhandler propertychanged; protected virtual void onpropertychanged(string propertyname) { var handler = propertychanged; if (handler != null) handler(this, new propertychangedeventargs(propertyname)); } private void fvdatabinding_selectionchanged(object sender, selectionchangedeventargs e) { } } }
bind filetext
property:
<textblock style="{staticresource logviewstyle}" text="{binding filetext, relativesource={relativesource mode=findancestor,ancestortype=window}}" x:name="logview" foreground="white" fontfamily="consolas" rendertransformorigin="0.415,0.382" grid.columnspan="2" margin="10,172,10,0"/>
it 1 set in readfile
method. there no property called logmessage
.
and don't have set datacontext
of window since specifying source of binding explicitly.
Comments
Post a Comment