c# - creating a common structure(theme) in WPF window -


i created windows form application inherit controls base form , works fine.

in wpf xaml possible inherit controls base form above?

when tried in visual studio, have got error showing:"'parentchild.mainwindow' cannot root of xaml file because defined using xaml".

my basewindow cs code:

namespace parentchild     {     public partial class basewindow : window         {             public basewindow()             {                 initializecomponent();             }         } } 

my basewindow xaml code:

<window         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon" x:class="parentchild.basewindow"         title="basewindow" height="350" width="525">     <grid>         <statusbar horizontalalignment="left" height="35" margin="0,285,0,0" verticalalignment="top" width="517">             <label content="label"/>             <label content="label"/>         </statusbar>     </grid> </window> 

my childwindow cs code:

namespace parentchild {     public partial class childwindow : basewindow     {         public childwindow()         {             initializecomponent();         }     } } 

my childwindow xaml code:

   <mn:basewindow x:class="parentchild.childwindow"             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:mn="clr-namespace:parentchild"             title="childwindow" height="300" width="300">         <grid>          </grid>     </mn:basewindow> 

i found solution creating user control , applying windows.is right way?

or have solution creating general theme/structure xaml windows.

please provide me solution solve issue.

you cannot inherit class has been defined in xaml. go creating usercontrol , using 'base container' in window want have status bar. if intent on making base window try this:

define base window in code only:

public class mywindowbase : window     {         private contentcontrol contentcontrol;          public mywindowbase()         {             this.createcontent();         }          public object basecontent         {             { return this.contentcontrol.content; }             set { this.contentcontrol.content = value; }         }          private void createcontent()         {             var grid = new grid();             var row1 = new rowdefinition() { height = new gridlength(1, gridunittype.star) };             var row2 = new rowdefinition() { height = gridlength.auto };             grid.rowdefinitions.add(row1);             grid.rowdefinitions.add(row2);              var statusbar = new statusbar() { height = 35, background = brushes.blue }; // initialize status bar how want.             grid.setrow(statusbar, 1);              this.contentcontrol = new contentcontrol();              grid.children.add(this.contentcontrol);             grid.children.add(statusbar);              base.content = grid;         }     } 

use base window in xaml this:

<wpfapplication7:mywindowbase xmlns:wpfapplication7="clr-namespace:wpfapplication7"  x:class="wpfapplication7.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="mainwindow" height="350" width="500">     <wpfapplication7:mywindowbase.basecontent>         <button>                     </button>     </wpfapplication7:mywindowbase.basecontent>     </wpfapplication7:mywindowbase>  

of course base class has room improvement, making basecontent dependency property, think demonstrates main idea.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -