Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all!

I have trivial problem which has been bugging me for some time, hope I can put it in words..

I have created customcontrol which inherits window. Basically its usage is as simply as using native wpf window + custom look and some extra methods with it.

My custom window works just fine when developing window which is startup window in wpf project. I can see my custom style in desingn mode and in the run.

The problem comes when I create predesigned custom window in codebehind I got my style but controls added into window wont show at all.

 // this is my custom control (window like). Style will apply BUT whatever predefined content wont appear!?

CustomWindow test = new CustomWindow (); 
test.Show();


I assume that there could be something wrong with style, I have defined free to desing area in my window style as follows

<adornerdecorator>
<contentpresenter margin="20" />
</adornerdecorator>


UPDATE:

Just noticed weird thing. When creating predefined window like this:

CustomWindow test = new CustomWindow (); 
Button btn = new Button();
btn.Content = "Hello";
test.Content = btn;
test.Show();


I get button into my custom window! So it seems that when creating custom window in codebehind it forgets its original xaml code where controls are placed in first place...

I hope you got idea :)

Cheers!
Posted
Updated 7-Nov-11 22:02pm
v3
Comments
Mark Salsbery 8-Nov-11 10:57am    
Nothing weird with the window. Window is a contentcontrol so has one single content object. If you set Content to something else then you replace the original.

1 solution

Hi all!

I found solution.. The weird thing is that in client side I have to call InitializeComponent(); method in constructor even I dont have that method my customwindow class.. go figure :S

Anyhow now I can create and show x pcs customwindows and each one apply styles and shows content as wanted! Took whole day to solve this :D

Cheers!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900