Windows Vista Beta | WinVistaBeta.com - Message | Exposing contained control properties from within a custom control

July 03, 2008  
Subject: Exposing contained control properties from within a custom control
Group: microsoft.public.windows.developer.winfx.avalon
Date: 4/10/2008 7:50:09 AM
From: "Martin Robins" [Email Address Protection]

This is a multi-part message in MIME format.

------=_NextPart_000_0006_01C89B22.8E661FF0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am trying to create a custom control that can be used to present a =
common look and feel within my application. My first start is to try and =
create a basic dialog using the following xaml ...

<Style TargetType=3D"{x:Type local:DialogBase}">
<Setter Property=3D"Template">
<Setter.Value>
<ControlTemplate TargetType=3D"{x:Type local:DialogBase}">
<Border Background=3D"{TemplateBinding Background}"
BorderBrush=3D"{TemplateBinding BorderBrush}"
BorderThickness=3D"{TemplateBinding =
BorderThickness}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height=3D"Auto"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row=3D"0" Margin=3D"5">
<TabControl Name=3D"PART_TabControl"/>
</DockPanel>

<DockPanel Grid.Row=3D"1" =
LastChildFill=3D"False" HorizontalAlignment=3D"Right" Margin=3D"5">
<Button IsDefault=3D"True">OK</Button>
<Button IsCancel=3D"True">Cancel</Button>
</DockPanel>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

I want to expose the Items property of the TabControl as the default =
property when I use this control so that I can use it like ...

<my:DialogBase ...>
<TabItem .../>
<TabItem.../>
</my:DialogBase>

I simply cannot work out how to do it (I am very new to WPF).

I have tried the following in code

namespace WpfCustomControlLibrary {
#region Namespace references
using System;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Controls;
using System.ComponentModel;
using System.Windows.Input;
using System.Collections.ObjectModel;
#endregion
[DefaultProperty("Items"), ContentProperty("Items")]
public class DialogBase : Window {
#region Fields
private TabControl tabControl;
#endregion
#region Constructor
static DialogBase() {
DefaultStyleKeyProperty.OverrideMetadata(typeof(DialogBase), =
new FrameworkPropertyMetadata(typeof(DialogBase)));
}
#endregion
[Bindable(true), =
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]=

public ItemCollection Items {
get { return this.tabControl.Items; }
}
#region Methods
public override void OnApplyTemplate() {
base.OnApplyTemplate();
this.tabControl =3D =
this.Template.FindName("PART_TabControl", this) as TabControl;
}
public Nullable<bool> ShowDialog(Window owner) {
this.Owner =3D owner;
return this.ShowDialog();
}
#endregion
}
}

But this fails because WPF attempts to merge the control xaml with the =
inner xaml before the OnApplyTemplate can work; therefore I end up with =
null reference exceptions because I cannot reference the tab control =
before the xaml is merged.

I am sure there is an easy way to do this but I cannot find it - and I =
have spent some considerable time on experiments and Google.

Anybody care to share?


Thanks


Martin.
------=_NextPart_000_0006_01C89B22.8E661FF0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16608" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I am trying to create a custom control =
that can be=20
used to present a common look and feel within my application. My first =
start is=20
to try and create a basic dialog using the following xaml =
....</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV><FONT face=3DArial =
size=3D2><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&lt;Style TargetType=3D"{x:Type local:DialogBase<FONT =
color=3D#0000ff=20
size=3D1><FONT color=3D#000000 size=3D2>}"&gt;</FONT></DIV></FONT><FONT =
color=3D#a31515=20
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &lt;Setter Property<FONT color=3D#0000ff=20
size=3D1><FONT color=3D#000000 =
size=3D2>=3D"Template"&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;Setter.Value<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000 =
size=3D2>&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;ControlTemplate TargetType=3D"{x:Type local:DialogBase<FONT =
color=3D#0000ff=20
size=3D1><FONT color=3D#000000 size=3D2>}"&gt;</FONT></DIV></FONT><FONT =
color=3D#a31515=20
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;Border Background=3D"{TemplateBinding =
Background<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000 =
size=3D2>}"</FONT></DIV></FONT><FONT=20
size=3D1>
<DIV></FONT><FONT color=3D#ff0000>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
BorderBrush</FONT><FONT=20
color=3D#0000ff>=3D"{</FONT><FONT =
color=3D#a31515>TemplateBinding</FONT><FONT=20
color=3D#ff0000> BorderBrush</FONT><FONT color=3D#0000ff size=3D1><FONT=20
size=3D2>}"</FONT></DIV></FONT><FONT size=3D1>
<DIV></FONT><FONT color=3D#ff0000>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
BorderThickness</FONT><FONT color=3D#0000ff>=3D"{</FONT><FONT=20
color=3D#a31515>TemplateBinding</FONT><FONT color=3D#ff0000>=20
BorderThickness</FONT><FONT color=3D#0000ff size=3D1><FONT=20
size=3D2>}"&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;Grid<FONT color=3D#0000ff =
size=3D1><FONT=20
color=3D#000000 size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 =
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;Grid.RowDefinitions<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;RowDefinition<FON=
T=20
color=3D#0000ff size=3D1><FONT color=3D#000000 size=3D2> =
/&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;RowDefinition Height<FONT color=3D#0000ff =
size=3D1><FONT=20
color=3D#000000 size=3D2>=3D"Auto"/&gt;</FONT></DIV></FONT><FONT =
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;/Grid.RowDefinitions<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;DockPanel=20
Grid.Row=3D"0" Margin<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>=3D"5"&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&lt;TabControl Name<FONT color=3D#0000ff size=3D1><FONT color=3D#000000=20
size=3D2>=3D"PART_TabControl"/&gt;</FONT></DIV></FONT><FONT =
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&lt;/DockPanel<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000 =
size=3D2>&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;DockPanel=20
Grid.Row=3D"1" LastChildFill=3D"False" HorizontalAlignment=3D"Right" =
Margin<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000=20
size=3D2>=3D"5"&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&lt;Button IsDefault=3D"True"&gt;OK&lt;/Button<FONT color=3D#0000ff =
size=3D1><FONT=20
color=3D#000000 size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 =
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&lt;Button IsCancel=3D"True"&gt;Cancel&lt;/Button<FONT color=3D#0000ff =
size=3D1><FONT=20
color=3D#000000 size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 =
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&lt;/DockPanel<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000 =
size=3D2>&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/Grid<FONT color=3D#0000ff =
size=3D1><FONT=20
color=3D#000000 size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 =
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;/Border<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;/ControlTemplate<FONT color=3D#0000ff size=3D1><FONT color=3D#000000 =

size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/Setter.Value<FONT =

color=3D#0000ff size=3D1><FONT color=3D#000000 =
size=3D2>&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &lt;/Setter<FONT color=3D#0000ff =
size=3D1><FONT=20
color=3D#000000 size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 =
size=3D1>
<DIV></FONT>&lt;/Style<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>&gt;</FONT></DIV></FONT></FONT>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I want to expose the Items property of =
the=20
TabControl as the default property when I use this control so that I can =
use it=20
like ...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &lt;my:DialogBase=20
....&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&lt;TabItem=20
..../&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;TabItem.../&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
&lt;/my:DialogBase&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I simply cannot work out how to do it =
(I am very=20
new to WPF).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have tried the following in =
code</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV><FONT face=3DArial =
size=3D2><FONT=20
color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>namespace</FONT></FONT><FONT =
size=3D1><FONT=20
size=3D2> WpfCustomControlLibrary {</FONT></DIV></FONT><FONT =
color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
#region</FONT></FONT><FONT=20
size=3D1><FONT size=3D2> Namespace references</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT=20
size=3D1><FONT size=3D2> System;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT=20
size=3D1><FONT size=3D2> System.Windows;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT=20
size=3D1><FONT size=3D2> System.Windows.Markup;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT=20
size=3D1><FONT size=3D2> System.Windows.Controls;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT=20
size=3D1><FONT size=3D2> System.ComponentModel;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT=20
size=3D1><FONT size=3D2> System.Windows.Input;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT=20
size=3D1><FONT size=3D2> =
System.Collections.ObjectModel;</FONT></DIV></FONT><FONT=20
color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp;=20
#endregion</FONT></DIV></FONT><FONT size=3D1>
<DIV></FONT><FONT size=3D2>&nbsp;&nbsp;&nbsp; [DefaultProperty(<FONT=20
color=3D#a31515>"Items"</FONT>), ContentProperty(<FONT=20
color=3D#a31515>"Items"</FONT>)]</FONT><FONT size=3D1></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; public</FONT> <FONT =

color=3D#0000ff>class</FONT> <FONT =
color=3D#2b91af>DialogBase</FONT><FONT=20
size=3D1><FONT size=3D2> : Window {</FONT></DIV></FONT><FONT =
color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#region</FONT></FONT><FONT size=3D1><FONT size=3D2> Fields</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
private</FONT><FONT size=3D1><FONT size=3D2> TabControl=20
tabControl;</FONT></DIV></FONT><FONT color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#endregion</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#region</FONT></FONT><FONT size=3D1><FONT size=3D2> =
Constructor</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
static</FONT><FONT size=3D1><FONT size=3D2> DialogBase() {</FONT></DIV>
<DIV></FONT><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; DefaultStyleKeyProperty.OverrideMetadata(<FONT=20
color=3D#0000ff>typeof</FONT>(DialogBase), <FONT =
color=3D#0000ff>new</FONT>=20
FrameworkPropertyMetadata(<FONT=20
color=3D#0000ff>typeof</FONT>(DialogBase)));</FONT><FONT size=3D1></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
}</FONT></DIV></FONT><FONT color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#endregion</FONT></DIV></FONT><FONT size=3D1>
<DIV></FONT><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
[Bindable(<FONT=20
color=3D#0000ff>true</FONT>),=20
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]=
</FONT><FONT=20
size=3D1></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
public</FONT><FONT size=3D1><FONT size=3D2> ItemCollection Items =
{</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; get</FONT> { <FONT color=3D#0000ff>return</FONT> =
<FONT=20
color=3D#0000ff>this</FONT><FONT size=3D1><FONT =
size=3D2>.tabControl.Items;=20
}</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
}</FONT></DIV></FONT><FONT color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#region</FONT></FONT><FONT size=3D1><FONT size=3D2> Methods</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
public</FONT> <FONT color=3D#0000ff>override</FONT> <FONT=20
color=3D#0000ff>void</FONT><FONT size=3D1><FONT size=3D2> =
OnApplyTemplate()=20
{</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; base</FONT><FONT size=3D1><FONT=20
size=3D2>.OnApplyTemplate();</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; this</FONT>.tabControl =3D <FONT=20
color=3D#0000ff>this</FONT>.Template.FindName(<FONT=20
color=3D#a31515>"PART_TabControl"</FONT>, <FONT =
color=3D#0000ff>this</FONT>) <FONT=20
color=3D#0000ff>as</FONT><FONT size=3D1><FONT size=3D2> =
TabControl;</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
public</FONT> <FONT color=3D#2b91af>Nullable</FONT>&lt;<FONT=20
color=3D#0000ff>bool</FONT><FONT size=3D1><FONT size=3D2>&gt; =
ShowDialog(Window owner)=20
{</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; this</FONT><FONT size=3D1><FONT size=3D2>.Owner =3D=20
owner;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; return</FONT> <FONT color=3D#0000ff>this</FONT><FONT=20
size=3D1><FONT size=3D2>.ShowDialog();</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
}</FONT></DIV></FONT><FONT color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#endregion</FONT></DIV></FONT><FONT size=3D1>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT size=3D2>}</FONT></DIV></FONT></FONT>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But this fails because WPF attempts to =
merge the=20
control&nbsp;xaml with the inner xaml before the OnApplyTemplate can =
work;=20
therefore I end up with null reference exceptions because I cannot =
reference the=20
tab control before the xaml is merged.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am sure there is an easy way to do =
this but I=20
cannot find it - and I have spent some considerable time on experiments =
and=20
Google.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Anybody care to share?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Martin.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0006_01C89B22.8E661FF0--


Back
Subject: Re: Exposing contained control properties from within a custom control
Group: microsoft.public.windows.developer.winfx.avalon
Date: 4/10/2008 7:53:49 AM
From: "Martin Robins" [Email Address Protection]

This is a multi-part message in MIME format.

------=_NextPart_000_001C_01C89B23.11615050
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Please refer to my repost rather than answer on this thread. Sorry; I =
missed a group in this post so I have reposted.
"Martin Robins" <martin at orpheus-solutions dot co dot uk> wrote in =
message news:eo9CwoxmIHA.6064@TK2MSFTNGP03.phx.gbl...
I am trying to create a custom control that can be used to present a =
common look and feel within my application. My first start is to try and =
create a basic dialog using the following xaml ...

<Style TargetType=3D"{x:Type local:DialogBase}">
<Setter Property=3D"Template">
<Setter.Value>
<ControlTemplate TargetType=3D"{x:Type local:DialogBase}">
<Border Background=3D"{TemplateBinding Background}"
BorderBrush=3D"{TemplateBinding BorderBrush}"
BorderThickness=3D"{TemplateBinding =
BorderThickness}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height=3D"Auto"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row=3D"0" Margin=3D"5">
<TabControl Name=3D"PART_TabControl"/>
</DockPanel>

<DockPanel Grid.Row=3D"1" =
LastChildFill=3D"False" HorizontalAlignment=3D"Right" Margin=3D"5">
<Button IsDefault=3D"True">OK</Button>
<Button IsCancel=3D"True">Cancel</Button>
</DockPanel>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

I want to expose the Items property of the TabControl as the default =
property when I use this control so that I can use it like ...

<my:DialogBase ...>
<TabItem .../>
<TabItem.../>
</my:DialogBase>

I simply cannot work out how to do it (I am very new to WPF).

I have tried the following in code

namespace WpfCustomControlLibrary {
#region Namespace references
using System;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Controls;
using System.ComponentModel;
using System.Windows.Input;
using System.Collections.ObjectModel;
#endregion
[DefaultProperty("Items"), ContentProperty("Items")]
public class DialogBase : Window {
#region Fields
private TabControl tabControl;
#endregion
#region Constructor
static DialogBase() {
=
DefaultStyleKeyProperty.OverrideMetadata(typeof(DialogBase), new =
FrameworkPropertyMetadata(typeof(DialogBase)));
}
#endregion
[Bindable(true), =
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]=

public ItemCollection Items {
get { return this.tabControl.Items; }
}
#region Methods
public override void OnApplyTemplate() {
base.OnApplyTemplate();
this.tabControl =3D =
this.Template.FindName("PART_TabControl", this) as TabControl;
}
public Nullable<bool> ShowDialog(Window owner) {
this.Owner =3D owner;
return this.ShowDialog();
}
#endregion
}
}

But this fails because WPF attempts to merge the control xaml with the =
inner xaml before the OnApplyTemplate can work; therefore I end up with =
null reference exceptions because I cannot reference the tab control =
before the xaml is merged.

I am sure there is an easy way to do this but I cannot find it - and I =
have spent some considerable time on experiments and Google.

Anybody care to share?


Thanks


Martin.
------=_NextPart_000_001C_01C89B23.11615050
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16608" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Please refer to my repost rather than =
answer on=20
this thread. Sorry; I missed a group in this post so I have=20
reposted.</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Martin Robins" &lt;martin at orpheus-solutions dot co dot uk&gt; =
wrote=20
in message <A=20
=
href=3D"news:eo9CwoxmIHA.6064@TK2MSFTNGP03.phx.gbl">news:eo9CwoxmIHA.6064=
@TK2MSFTNGP03.phx.gbl</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>I am trying to create a custom =
control that can=20
be used to present a common look and feel within my application. My =
first=20
start is to try and create a basic dialog using the following xaml=20
...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV><FONT face=3DArial =
size=3D2><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&lt;Style TargetType=3D"{x:Type local:DialogBase<FONT =
color=3D#0000ff=20
size=3D1><FONT color=3D#000000 =
size=3D2>}"&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &lt;Setter Property<FONT =
color=3D#0000ff=20
size=3D1><FONT color=3D#000000 =
size=3D2>=3D"Template"&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&lt;Setter.Value<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000 =
size=3D2>&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;ControlTemplate TargetType=3D"{x:Type local:DialogBase<FONT =
color=3D#0000ff=20
size=3D1><FONT color=3D#000000 =
size=3D2>}"&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;Border Background=3D"{TemplateBinding =
Background<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000 =
size=3D2>}"</FONT></DIV></FONT><FONT=20
size=3D1>
<DIV></FONT><FONT color=3D#ff0000>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
BorderBrush</FONT><FONT color=3D#0000ff>=3D"{</FONT><FONT=20
color=3D#a31515>TemplateBinding</FONT><FONT color=3D#ff0000>=20
BorderBrush</FONT><FONT color=3D#0000ff size=3D1><FONT=20
size=3D2>}"</FONT></DIV></FONT><FONT size=3D1>
<DIV></FONT><FONT color=3D#ff0000>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
BorderThickness</FONT><FONT color=3D#0000ff>=3D"{</FONT><FONT=20
color=3D#a31515>TemplateBinding</FONT><FONT color=3D#ff0000>=20
BorderThickness</FONT><FONT color=3D#0000ff size=3D1><FONT=20
size=3D2>}"&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;Grid<FONT color=3D#0000ff =
size=3D1><FONT=20
color=3D#000000 size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 =
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;Grid.RowDefinitions<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
=
<DIV></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;RowDefinition<FON=
T=20
color=3D#0000ff size=3D1><FONT color=3D#000000 size=3D2>=20
/&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;RowDefinition Height<FONT color=3D#0000ff =
size=3D1><FONT=20
color=3D#000000 size=3D2>=3D"Auto"/&gt;</FONT></DIV></FONT><FONT =
color=3D#a31515=20
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;/Grid.RowDefinitions<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;DockPanel =

Grid.Row=3D"0" Margin<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>=3D"5"&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&lt;TabControl Name<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>=3D"PART_TabControl"/&gt;</FONT></DIV></FONT><FONT =
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&lt;/DockPanel<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000 =
size=3D2>&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;DockPanel =

Grid.Row=3D"1" LastChildFill=3D"False" HorizontalAlignment=3D"Right" =
Margin<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000=20
size=3D2>=3D"5"&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&lt;Button IsDefault=3D"True"&gt;OK&lt;/Button<FONT color=3D#0000ff =
size=3D1><FONT=20
color=3D#000000 size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 =
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&lt;Button IsCancel=3D"True"&gt;Cancel&lt;/Button<FONT color=3D#0000ff =

size=3D1><FONT color=3D#000000 size=3D2>&gt;</FONT></DIV></FONT><FONT =
color=3D#a31515=20
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&lt;/DockPanel<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000 =
size=3D2>&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/Grid<FONT color=3D#0000ff=20
size=3D1><FONT color=3D#000000 size=3D2>&gt;</FONT></DIV></FONT><FONT =
color=3D#a31515=20
size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;/Border<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;/ControlTemplate<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&lt;/Setter.Value<FONT=20
color=3D#0000ff size=3D1><FONT color=3D#000000 =
size=3D2>&gt;</FONT></DIV></FONT><FONT=20
color=3D#a31515 size=3D1>
<DIV></FONT>&nbsp;&nbsp;&nbsp; &lt;/Setter<FONT color=3D#0000ff =
size=3D1><FONT=20
color=3D#000000 size=3D2>&gt;</FONT></DIV></FONT><FONT color=3D#a31515 =
size=3D1>
<DIV></FONT>&lt;/Style<FONT color=3D#0000ff size=3D1><FONT =
color=3D#000000=20
size=3D2>&gt;</FONT></DIV></FONT></FONT>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I want to expose the Items property =
of the=20
TabControl as the default property when I use this control so that I =
can use=20
it like ...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &lt;my:DialogBase=20
...&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&lt;TabItem=20
.../&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

&lt;TabItem.../&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
&lt;/my:DialogBase&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I simply cannot work out how to do it =
(I am very=20
new to WPF).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have tried the following in =
code</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV><FONT face=3DArial =
size=3D2><FONT=20
color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>namespace</FONT></FONT><FONT =
size=3D1><FONT=20
size=3D2> WpfCustomControlLibrary {</FONT></DIV></FONT><FONT =
color=3D#0000ff=20
size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
#region</FONT></FONT><FONT=20
size=3D1><FONT size=3D2> Namespace references</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT =

size=3D1><FONT size=3D2> System;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT =

size=3D1><FONT size=3D2> System.Windows;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT =

size=3D1><FONT size=3D2> System.Windows.Markup;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT =

size=3D1><FONT size=3D2> System.Windows.Controls;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT =

size=3D1><FONT size=3D2> System.ComponentModel;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT =

size=3D1><FONT size=3D2> System.Windows.Input;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; using</FONT><FONT =

size=3D1><FONT size=3D2> =
System.Collections.ObjectModel;</FONT></DIV></FONT><FONT=20
color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp;=20
#endregion</FONT></DIV></FONT><FONT size=3D1>
<DIV></FONT><FONT size=3D2>&nbsp;&nbsp;&nbsp; [DefaultProperty(<FONT=20
color=3D#a31515>"Items"</FONT>), ContentProperty(<FONT=20
color=3D#a31515>"Items"</FONT>)]</FONT><FONT size=3D1></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; public</FONT> =
<FONT=20
color=3D#0000ff>class</FONT> <FONT =
color=3D#2b91af>DialogBase</FONT><FONT=20
size=3D1><FONT size=3D2> : Window {</FONT></DIV></FONT><FONT =
color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#region</FONT></FONT><FONT size=3D1><FONT size=3D2> =
Fields</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
private</FONT><FONT size=3D1><FONT size=3D2> TabControl=20
tabControl;</FONT></DIV></FONT><FONT color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#endregion</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#region</FONT></FONT><FONT size=3D1><FONT size=3D2> =
Constructor</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
static</FONT><FONT size=3D1><FONT size=3D2> DialogBase() =
{</FONT></DIV>
<DIV></FONT><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; DefaultStyleKeyProperty.OverrideMetadata(<FONT=20
color=3D#0000ff>typeof</FONT>(DialogBase), <FONT =
color=3D#0000ff>new</FONT>=20
FrameworkPropertyMetadata(<FONT=20
color=3D#0000ff>typeof</FONT>(DialogBase)));</FONT><FONT =
size=3D1></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
}</FONT></DIV></FONT><FONT color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#endregion</FONT></DIV></FONT><FONT size=3D1>
<DIV></FONT><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
[Bindable(<FONT=20
color=3D#0000ff>true</FONT>),=20
=
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]=
</FONT><FONT=20
size=3D1></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
public</FONT><FONT size=3D1><FONT size=3D2> ItemCollection Items =
{</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; get</FONT> { <FONT color=3D#0000ff>return</FONT> =
<FONT=20
color=3D#0000ff>this</FONT><FONT size=3D1><FONT =
size=3D2>.tabControl.Items;=20
}</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
}</FONT></DIV></FONT><FONT color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#region</FONT></FONT><FONT size=3D1><FONT size=3D2> =
Methods</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
public</FONT> <FONT color=3D#0000ff>override</FONT> <FONT=20
color=3D#0000ff>void</FONT><FONT size=3D1><FONT size=3D2> =
OnApplyTemplate()=20
{</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; base</FONT><FONT size=3D1><FONT=20
size=3D2>.OnApplyTemplate();</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; this</FONT>.tabControl =3D <FONT=20
color=3D#0000ff>this</FONT>.Template.FindName(<FONT=20
color=3D#a31515>"PART_TabControl"</FONT>, <FONT =
color=3D#0000ff>this</FONT>) <FONT=20
color=3D#0000ff>as</FONT><FONT size=3D1><FONT size=3D2> =
TabControl;</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
}</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
public</FONT> <FONT color=3D#2b91af>Nullable</FONT>&lt;<FONT=20
color=3D#0000ff>bool</FONT><FONT size=3D1><FONT size=3D2>&gt; =
ShowDialog(Window=20
owner) {</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; this</FONT><FONT size=3D1><FONT size=3D2>.Owner =3D =

owner;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; return</FONT> <FONT =
color=3D#0000ff>this</FONT><FONT=20
size=3D1><FONT size=3D2>.ShowDialog();</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
}</FONT></DIV></FONT><FONT color=3D#0000ff size=3D1>
<DIV><FONT color=3D#000000 size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
#endregion</FONT></DIV></FONT><FONT size=3D1>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT size=3D2>}</FONT></DIV></FONT></FONT>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But this fails because WPF attempts =
to merge the=20
control&nbsp;xaml with the inner xaml before the OnApplyTemplate can =
work;=20
therefore I end up with null reference exceptions because I cannot =
reference=20
the tab control before the xaml is merged.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am sure there is an easy way to do =
this but I=20
cannot find it - and I have spent some considerable time on =
experiments and=20
Google.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Anybody care to share?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>Martin.</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_001C_01C89B23.11615050--


Back