Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

How do I create for example a dockpanel in xaml and add elements form the code-behind?

Closed Thread
 
Thread Tools Display Modes
Old 04-28-2006   #1 (permalink)
HokutoNoKen
Guest


 

How do I create for example a dockpanel in xaml and add elements form the code-behind?

Hi,

If I create a dockpanel in my Window1.xaml like this:

<Window x:Class="WindowsApplication8.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowsApplication8" Height="300" Width="300"
>


<DockPanel x:Name="myDockPanel">

</DockPanel>

</Window>

How shall I add for example a button to my dockpanel form my code behind
(Window1.xaml.cs)?

What I have tried in my code-behind.

Button myButton = new Button();
myButton.Content = "Please Help";

DockPanel.SetDock(myButton, Dock.Top);
myDockPanel.Children.Add(myButton);
this.Content = myDockPanel;

/ Tommy





Old 04-28-2006   #2 (permalink)
viliescu
Guest


 

RE: How do I create for example a dockpanel in xaml and add elements f

You don't have to set the window's content to the dock panel again. So this
line ( this.Content = myDockPanel; ) can be removed. Other than that, the
sample should work fine.
--
Valentin Iliescu [MVP - Client Application Development]


"HokutoNoKen" wrote:

> Hi,
>
> If I create a dockpanel in my Window1.xaml like this:
>
> <Window x:Class="WindowsApplication8.Window1"
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> Title="WindowsApplication8" Height="300" Width="300"
> >

>
> <DockPanel x:Name="myDockPanel">
>
> </DockPanel>
>
> </Window>
>
> How shall I add for example a button to my dockpanel form my code behind
> (Window1.xaml.cs)?
>
> What I have tried in my code-behind.
>
> Button myButton = new Button();
> myButton.Content = "Please Help";
>
> DockPanel.SetDock(myButton, Dock.Top);
> myDockPanel.Children.Add(myButton);
> this.Content = myDockPanel;
>
> / Tommy
>
>
>
>
>
>

Old 04-28-2006   #3 (permalink)
viliescu
Guest


 

RE: How do I create for example a dockpanel in xaml and add elements f

I forgot something, by default DockPanel has LastChildFill=true so it will
disregard the Dock value. Set it to false to make the sample work.

--
Valentin Iliescu [MVP - Client Application Development]


"HokutoNoKen" wrote:

> Hi,
>
> If I create a dockpanel in my Window1.xaml like this:
>
> <Window x:Class="WindowsApplication8.Window1"
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> Title="WindowsApplication8" Height="300" Width="300"
> >

>
> <DockPanel x:Name="myDockPanel">
>
> </DockPanel>
>
> </Window>
>
> How shall I add for example a button to my dockpanel form my code behind
> (Window1.xaml.cs)?
>
> What I have tried in my code-behind.
>
> Button myButton = new Button();
> myButton.Content = "Please Help";
>
> DockPanel.SetDock(myButton, Dock.Top);
> myDockPanel.Children.Add(myButton);
> this.Content = myDockPanel;
>
> / Tommy
>
>
>
>
>
>

Old 05-04-2006   #4 (permalink)
Tommy Larsson
Guest


 

Re: How do I create for example a dockpanel in xaml and add elements form the code-behind?

Add loaded, se below and the eventhandler Windowloaded in the code behind

Window1.xaml :

<Window x:Class="WindowsApplication8.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="WindowsApplication10" Height="300" Width="300"

Loaded="WindowLoaded"

>


<Window.Resources>

<Ellipse x:Key="shape" Fill="Blue" Width="100" Height="80" />



</Window.Resources>

<DockPanel x:Name="myDockPanel"></DockPanel>

</Window>



Window1.xaml.cs:

private void WindowLoaded(object sender, RoutedEventArgs e)

{

// Add button

Button myButton = new Button();

myButton.Content = "Click me!";

this.myDockPanel.Children.Add(myButton);

Ellipse myEllipse = (Ellipse)this.FindResource("shape");

this.myDockPanel.Children.Add(myEllipse);

}

This also solve the question about resources ("Resources doesn´t work at
all?"), this code should also be here (as you see in the example code above
with the ellipse)

Regards,

Tommy




"HokutoNoKen" <tommy.herceg@programgruppen.se> wrote in message
news:enYGEXpaGHA.1352@TK2MSFTNGP05.phx.gbl...
> Hi,
>
> If I create a dockpanel in my Window1.xaml like this:
>
> <Window x:Class="WindowsApplication8.Window1"
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> Title="WindowsApplication8" Height="300" Width="300"
> >

>
> <DockPanel x:Name="myDockPanel">
>
> </DockPanel>
>
> </Window>
>
> How shall I add for example a button to my dockpanel form my code behind
> (Window1.xaml.cs)?
>
> What I have tried in my code-behind.
>
> Button myButton = new Button();
> myButton.Content = "Please Help";
>
> DockPanel.SetDock(myButton, Dock.Top);
> myDockPanel.Children.Add(myButton);
> this.Content = myDockPanel;
>
> / Tommy
>
>
>
>
>



Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a form that can be e-mailed Natasha Vista account administration 4 05-22-2007 12:32 PM
Create a New Form Jorge Benjumea Vista General 1 05-15-2007 08:38 PM
place net 2.0 control on xaml form Dirk Reske Avalon 5 02-17-2007 03:02 PM
HowTo: Create Windows Form without Stopping the Script from Processing Brandon Shell PowerShell 7 09-15-2006 05:24 PM
Should New-Item consistently create needed path elements? Alex K. Angelopoulos [MVP] PowerShell 3 06-04-2006 08:09 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50