c# - WPF Binding not updating Visibility -


i'm having trouble binding visibility of grid. i've had projects i've done before , have tried replicate same coding used previously, , i've searched around , added in bool visibility converter based off other articles still nothing.

all trying far in project have set of options provided user. when select 1 option either bring sub-options or take them proper area. have binding set bool object , have @ times created little message boxes , others let me know if program reaching everywhere. every messagebox along way, appears reaching every piece of code.

can shed light on doing wrong or point me in correct direction?

converter in windows.resources (edited show code in windows.resources)

<window.resources>     <style targettype="{x:type button}">         <setter property="fontsize" value="15"/>         <setter property="fontweight" value="bold" />         <setter property="height" value="50" />         <setter property="width" value="100" />         <setter property="margin" value="0,0,0,0" />         <setter property="horizontalalignment" value="center" />         <setter property="verticalalignment" value="center" />     </style>     <booleantovisibilityconverter x:key="booleantovisibilityconverter" /> </window.resources> 

code in rest of window

<grid>     <grid x:name="grid_mainmenu" visibility="{binding mainmenuvisibility, converter={staticresource booleantovisibilityconverter}}" margin="0,0,0,20">         <grid.rowdefinitions>             <rowdefinition height="1*"/>             <rowdefinition height="1*"/>         </grid.rowdefinitions>         <button x:name="button_items" content="items" grid.row="0" click="button_items_click"/>         <button x:name="button_orders" content="orders" grid.row="1" click="button_orders_click" />         <textbox text="{binding statusmessage, mode=twoway, updatesourcetrigger=propertychanged}" margin="0,0,0,0" horizontalalignment="left"  verticalalignment="top" height="100" width="100"/>     </grid>     <grid x:name="grid_itemmenu" visibility="{binding itemmenuvisibility, converter={staticresource booleantovisibilityconverter}}" margin="0,0,0,20">         <grid.rowdefinitions>             <rowdefinition height="auto"/>             <rowdefinition height="1*"/>             <rowdefinition height="1*"/>         </grid.rowdefinitions>         <label content="item menu" grid.row="0" fontsize="20" fontweight="bold" margin="0,0,0,0" horizontalalignment="center" verticalalignment="center"/>         <button grid.row="1" x:name="button_itemmaintenance" content="maintenance"/>         <button grid.row="2" x:name="button_itemcreation" content="create"/>     </grid>     <dockpanel height="25" margin="0,0,0,0" verticalalignment="bottom">         <statusbar dockpanel.dock="bottom">             <statusbaritem>                 <textblock text="{binding statusmessage, mode=twoway, updatesourcetrigger=propertychanged}"/>             </statusbaritem>         </statusbar>     </dockpanel> </grid> 

here code in class

    public bool mainmenuvisibility     {         { return _mainmenuvisibility; }         set { _mainmenuvisibility = value; raisepropertychanged(); }     }      public bool itemmenuvisibility     {         { return _itemmenuvisibility; }         set         { _itemmenuvisibility = value; raisepropertychanged(); }     }      public bool ordermenuvisibility     {         { return _ordermenuvisibility; }         set { _ordermenuvisibility = value;  raisepropertychanged(); }     } 

main constructor

public menu_view()     {         showmainmenu();     } 

a couple of controls

public void showmainmenu()     {         mainmenuvisibility = true;         hideitemmenu();         hideordermenu();         statusmessage = "showing main menu";     }      public void hidemainmenu()     {         mainmenuvisibility = false;         statusmessage = "hid main menu";     }      public void showitemmenu()     {         try         {             //reaches, never updates             itemmenuvisibility = true;             hidemainmenu();             hideordermenu();         }         catch(exception error)         {             //never shows here             statusmessage = "failed load item menu";         }                 {             //does not update, reaches here             statusmessage = "showing item menu";         }     } 

program starts showing main menu, when user clicks button items supposed show item menu. button click calls showitemmenu(). have verified that happen , called in proper order.

i have verified showitemmenu() work putting in constructor instead of showmainmenu(). either 1 works fine, neither cause update after initial loading though reached after button presses.

sorry if did not include needed.

edit:

i believe had 2 issues going on simultaneously. 1 improperly configured data converter. answer , reference below.

as issue in window code here:

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

i believe part of issue. creating menuview of type menu_view. on initialize assigned menuview new menu_view() , assigned datacontext new menu_view() instead of menuview. commands updating menuview , updating 1 assigned datacontext.

add converter class project.

 class booleantovisibilityconverter : ivalueconverter {     public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         if (value boolean && (bool)value)         {             return visibility.visible;         }         return visibility.collapsed;     }      public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         if (value visibility && (visibility)value == visibility.visible)         {             return true;         }         return false;     } } 

referance


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -