c# - WPF auto expand then error not work -


i have problem in wpf application.  in xaml:          <expander header="someheader" style="{staticresource expanderstyle}" isexpanded="{binding elementname=errors, converter={staticresource visibilityconverter}, path=isexpanded}"  >                 <richtextbox scrollviewer.verticalscrollbarvisibility="visible" style="{staticresource richtextboxstyle}" foreground="red" isreadonly="true">                         <flowdocument>                             <paragraph>                                 <itemscontrol itemssource="{binding path=errors}">                                     <itemscontrol.itemtemplate>                                         <datatemplate>                                             <textblock text="{binding}" style="{staticresource errortextblockstyle}"/>                                         </datatemplate>                                     </itemscontrol.itemtemplate>                                 </itemscontrol>                             </paragraph>                         </flowdocument>                     </richtextbox>             </expander>     in viewmodelclass:            private list<string> errors;        public list<string> errors        {             { return errors; }             set             {                 errors = value;                 onpropertychanged("errors");             }        }       

in constructor:

       public mainwindowviewmodel()        {                if (isindesignmode) return;                errors = new list<string>();            }     

in test method:

       private void testexcute()        {            errors = "some error";            } 

in situation error message not displayed in wpf window. if change code in constructor next:

      public mainwindowviewmodel()       {                if (isindesignmode) return;                errors = new list<string>{"errormessage1", "errormessage2"};           } 

displayed:

errormessage1

errormessage2

what reason ?

i have new question. in wpf application used expander control. how create auto expand open, errors.count > 0?

i create converter :

public class visibilityconverter : ivalueconverter { public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { loadfile loadfile = (loadfile)value;

        if (loadingfile.excelerrors.count > 0)         {             return visibility.visible;         }         else         {             return visibility.collapsed;         }     }      public object convertback(object value, type targettype,         object parameter, system.globalization.cultureinfo culture)     {         throw new notimplementedexception();     } } 

loadfile class declared errors property.

i think made error in testexcute while writing question did mean write errors.add("some error")?

if itemscontrol wont react change because there no change on property errors - setter not invoked.

change list<string> observablecollection<string> class notifies content has change , ui react that.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -