c# - WPF Custom Control in separate namesapce -


i try make visual c# app, using usercontrol (wpf). default, vs community 2015 c# generates usercontrol in same namespace main program. it's built correctly. i'd separate in it's own namespace possible future reuse. change auto-generated code have usercontrol in separate namespace.

here code

usercontrol

<usercontrol x:class="nstabi2cmemrw.tabi2cmemrw"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"          xmlns:local="clr-namespace:nstabi2cmemrw"          mc:ignorable="d"           d:designheight="300" d:designwidth="500">      <grid>         <textbox x:name="addrh"/>         <label x:name="addrh_label"/>     </grid> 

c# class

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes; using wpfapplication1;    // main app namespace  namespace nstabi2cmemrw {     /// <summary>     /// interaction logic tabi2cmemrw.xaml     /// </summary>     public partial class tabi2cmemrw : usercontrol     {         public tabi2cmemrw()         {             //initializecomponent();             ((wpfapplication1.mainwindow)application.current.mainwindow).initializecomponent();  //initializecomponent();         }     } } 

main windows xaml

<window x:class="wpfapplication1.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     xmlns:local="clr-namespace:wpfapplication1"     xmlns:usercontrol="clr-namespace:nstabi2cmemrw"     mc:ignorable="d"     title="mainwindow" height="649.005" width="620.667" scrollviewer.cancontentscroll="true"> <grid>     <tabcontrol x:name="tabcontrol" margin="0,0,0.4,0.2">         <tabcontrol.bindinggroup>             <bindinggroup/>         </tabcontrol.bindinggroup>         <tabitem x:name="i2cmemreadwrite" header="i2c mem read/write">              <usercontrol:tabi2cmemrw margin="0,0,-0.2,278.2"/>          </tabitem>          <tabitem header="tabitem">         <button x:name="button" content="button" height="100" width="75"/>         </tabitem>      </tabcontrol>  </grid> 

designer shows error "object reference not set instance of object" line

<usercontrol:tabi2cmemrw margin="0,0,-0.2,278.2"/> 

program compiled fine first tab (where usercontrol should be) blank.

there many things wrong here, cant answer them all. try comenting ((wpfapplication1.mainwindow)application.current.mainwindow).initializecomponent();

and leaving

initializecomponent();

instead in c# class


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -