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

Go Back   Vista Forums > Vista technology newsgroups > Avalon

Exposing contained control properties from within a custom control

Reply
 
Thread Tools Display Modes
Old 04-10-2008   #1
Martin Robins
Guest
 
Posts: n/a

Exposing contained control properties from within a custom control

NOTE: Reposted because I missed a group in the original post.

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="{x:Type localialogBase}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type localialogBase}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" Margin="5">
<TabControl Name="PART_TabControl"/>
</DockPanel>

<DockPanel Grid.Row="1" LastChildFill="False" HorizontalAlignment="Right" Margin="5">
<Button IsDefault="True">OK</Button>
<Button IsCancel="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 ...

<myialogBase ...>
<TabItem .../>
<TabItem.../>
</myialogBase>

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 = this.Template.FindName("PART_TabControl", this) as TabControl;
}
public Nullable<bool> ShowDialog(Window owner) {
this.Owner = 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.

  Reply With Quote

Reply

Thread Tools
Display Modes









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