wpf - Why is my busy page not working? -



wpf - Why is my busy page not working? -

i'm trying develop busy window said here , here. want grid visible whenver need visible, illustration while i'm doing long task.

i did til now:

the xaml:

<window x:class="loadingwindow2.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:loadingwindow2="clr-namespace:loadingwindow2" title="mainwindow" height="350" width="525"> <window.resources> <loadingwindow2:booltovisibilityconverter x:key="boolconverter"/> </window.resources> <grid> <label horizontalalignment="right"> <hyperlink command="{binding path=dosomething}">do something</hyperlink> </label> <border borderbrush="black" borderthickness="1" background="#80000000" visibility="{binding isbusy, converter={staticresource boolconverter}}" grid.rowspan="3"> <grid> <textblock margin="0" textwrapping="wrap" text="please wait..." horizontalalignment="center" verticalalignment="center" fontsize="24" fontweight="bold" foreground="#7effffff"/> </grid> </border> </grid>

my .cs:

the busyviewmodel.cs:

public class busyviewmodel : inotifypropertychanged { private icommand dosomethingcommand; public event propertychangedeventhandler propertychanged; public bool isbusy { get; set; } public icommand dosomething { { homecoming dosomethingcommand ?? (dosomethingcommand = new delegatecommand(longrunningtask)); } } private void longrunningtask() { var task = new task(computeresults); task.start(); } private void computeresults() { this.isbusy = true; thread.sleep(5000); this.isbusy = false; } }

the delegatecommand.cs:

public class delegatecommand : icommand { private readonly action executemethod; private readonly func<bool> canexecutemethod; public delegatecommand(action executemethod) : this(executemethod, () => true) { } public delegatecommand(action executemethod, func<bool> canexecutemethod) { if (executemethod == null) throw new argumentnullexception("executemethod"); if (canexecutemethod == null) throw new argumentnullexception("canexecutemethod"); this.executemethod = executemethod; this.canexecutemethod = canexecutemethod; } public event eventhandler canexecutechanged { add together { commandmanager.requerysuggested += value; } remove { commandmanager.requerysuggested -= value; } } public bool canexecute(object stupid) { homecoming canexecute(); } public bool canexecute() { homecoming canexecutemethod(); } public void execute(object parameter) { execute(); } public void execute() { executemethod(); } public void oncanexecutechanged() { commandmanager.invalidaterequerysuggested(); } }

mainwindow.xaml.cs:

public mainwindow() { initializecomponent(); this.datacontext = new busyviewmodel(); }

i downloaded source code first link copied, , busy grid showing. in case... not!!! i'm doing wrong here?

edit: deleted converter suggested. it's not working yet... add together `mainwindow.xaml.cs"

the whole source: here

there converter available wpf already, "booleantovisibilityconverter" job.

see http://msdn.microsoft.com/de-de/library/system.windows.controls.booleantovisibilityconverter%28v=vs.110%29.aspx

edit xaml this:

<window x:class="loadingwindow2.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:loadingwindow2="clr-namespace:loadingwindow2" title="mainwindow" height="350" width="525"> <window.resources> <booleantovisibilityconverter x:key="boolconverter"/> </window.resources> <grid x:name="root"> <label horizontalalignment="right"> <hyperlink command="{binding path=dosomething}">do something</hyperlink> </label> <border borderbrush="black" borderthickness="1" background="#80000000" visibility="{binding path=isbusy, converter={staticresource boolconverter}}" grid.rowspan="3"> <grid> <textblock margin="0" textwrapping="wrap" text="please wait..." horizontalalignment="center" verticalalignment="center" fontsize="24" fontweight="bold" foreground="#7effffff"/> </border> </grid>

edit: implementation of busyviewmodel

public class busyviewmodel : inotifypropertychanged { private icommand dosomethingcommand; public event propertychangedeventhandler propertychanged; private bool _isbusy = false; public bool isbusy { { homecoming _isbusy; } set { _isbusy = value; onpropertychanged("isbusy"); } } // create onpropertychanged method raise event protected void onpropertychanged(string name) { propertychangedeventhandler handler = propertychanged; if (handler != null) { handler(this, new propertychangedeventargs(name)); } } public icommand dosomething { { homecoming dosomethingcommand ?? (dosomethingcommand = new delegatecommand(longrunningtask)); } } private void longrunningtask() { var task = new task(computeresults); task.start(); } private void computeresults() { this.isbusy = true; thread.sleep(5000); this.isbusy = false; } }

see http://msdn.microsoft.com/de-de/library/ms743695%28v=vs.110%29.aspx

edit: seek set info context on root grid giving grid name , instead of this.datacontext = ... in public mainwindow() ...do root.datacontext = .... see updated xaml!

edit: got working. see code of class busyviewmodel.

private void longrunningtask() { var task = new task(computeresults); task.start(); } private void computeresults() { this.isbusy = true; // did _isbusy = true. invoke onpropertychanged need utilize setter, isbusy! works if set in worker thread. set computeresults! thread.sleep(5000); this.isbusy = false; }

wpf xaml binding

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -