c# - How to choose grid Columns from some Tabs and display them in another Tab? -


i'm creating wpf application(ui) tabcontrol contains 4 tabitems in it. my application -- user tab, want choose somehow (maybe check box, or other way) of gridcolumns displayed @ user tab. can work other tabs, need give user opportunity work specific outputs he/she wants. how can make work? new c# , wpf, if explain simple solution , offer codes, appriciate it.

before answering question, brief hint you: when ask, post code, otherwise hard spends time helping you.

for implementing application need consider:

  1. elementname data binding
  2. elementname data binding can't work in columndefinitions property

to solve point number 2 can read interesting article josh smith.

pratically creates special kind of elementspy attached property:

public class elementspy : freezable {     private dependencyobject element;      public static elementspy getnamescopesource(dependencyobject obj)     {         return (elementspy)obj.getvalue(namescopesourceproperty);     }      public static void setnamescopesource(dependencyobject obj, elementspy value)     {         obj.setvalue(namescopesourceproperty, value);     }      public static readonly dependencyproperty namescopesourceproperty =         dependencyproperty.registerattached("namescopesource", typeof(elementspy), typeof(elementspy),             new uipropertymetadata(null, onnamescopesourceproperty));      private static void onnamescopesourceproperty(dependencyobject d, dependencypropertychangedeventargs args)     {         inamescope namescope;         elementspy elementspy = args.newvalue elementspy;          if (elementspy != null && elementspy.element != null)         {             namescope = namescope.getnamescope(elementspy.element);             if (namescope != null)             {                 d.dispatcher.begininvoke(new action<dependencyobject, inamescope>(setscope),                     system.windows.threading.dispatcherpriority.normal,                     d, namescope);             }         }     }      private static void setscope(dependencyobject d, inamescope namescope)     {         namescope.setnamescope(d, namescope);     }      public dependencyobject element     {                 {             if (element == null)             {                 propertyinfo propertyinfo = typeof(freezable).getproperty("inheritancecontext",                     bindingflags.nonpublic | bindingflags.instance);                  element = propertyinfo.getvalue(this, null) dependencyobject;                  if (element != null)                 {                     freeze();                 }             }              return element;         }     }      protected override freezable createinstancecore()     {         return new elementspy();     } } 

now can use binding in our xaml

<window.resources>     <local:booleanwidthconverter x:key="booleanwidthconverter" />     <local:elementspy x:key="elementspy" /> </window.resources>      <stackpanel horizontalalignment="stretch">     <grid local:elementspy.namescopesource="{staticresource elementspy}"             margin="0,0,0,30">         <grid.rowdefinitions>             <rowdefinition height="auto" />         </grid.rowdefinitions>         <grid.columndefinitions>             <columndefinition width="{binding elementname=cb1, path=ischecked, converter={staticresource booleanwidthconverter}, mode=oneway}" />             <columndefinition width="{binding elementname=cb2, path=ischecked, converter={staticresource booleanwidthconverter}, mode=oneway}" />             <columndefinition width="{binding elementname=cb3, path=ischecked, converter={staticresource booleanwidthconverter}, mode=oneway}" />         </grid.columndefinitions>          <textblock horizontalalignment="center" text="column 1" margin="4" grid.column="0" />         <textblock horizontalalignment="center" text="column 2" margin="4" grid.column="1" />         <textblock horizontalalignment="center" text="column 3" margin="4" grid.column="2" />      </grid>      <checkbox x:name="cb1" content="column 1" margin="4" ischecked="true" horizontalalignment="center" />     <checkbox x:name="cb2" content="column 2" margin="4" ischecked="true" horizontalalignment="center" />     <checkbox x:name="cb3" content="column 3" margin="4" ischecked="true" horizontalalignment="center" /> </stackpanel> 

to complete our code, need simple converter:

public class booleanwidthconverter : ivalueconverter {     private static gridlength star = new gridlength(1, gridunittype.star);     private static gridlength 0 = new gridlength(0, gridunittype.pixel);      public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         bool boolvalue = (bool)value;          return boolvalue ? star : zero;     }      public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         throw new notimplementedexception();     } } 

of course sample prototype, sure can application.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -