Hi, i have the following scenario:
[TemplatePart(Name = GoToEditModeButtonPart, Type = typeof(DoubleClickButton))]
public class ValueBoxWithLabel : ContentControl
{
public const string GoToEditModeButtonPart = "GoToEditModeButtonPart";
#region LabelText Dependency Property ...
#region IsInEditMode Dependency Property ...
public event EventHandler<ModeChangedEventArgs> ModeChanged;
public ValueBoxWithLabel()
{
DefaultStyleKey = typeof (ValueBoxWithLabel);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
//IsInEditMode invokes ModeChanged in the dependency property
((DoubleClickButton) GetTemplateChild(GoToEditModeButtonPart)).DoubleClick += (sender, args) => IsInEditMode = true;
}
private void InvokeModeChanged(ModeChangedEventArgs e)
{
EventHandler<ModeChangedEventArgs> mode = ModeChanged;
if (mode != null)
mode(this, e);
}
}
ValueBox is essential a panel for any inputbox. It is simple now, but will be reused throughout the application, and will contain more complex behavoir and layout.
TextBox as input is the must used, therefore i make this Control:
public class TextBoxWithLabel : ValueBoxWithLabel
{
#region Text Dependency Property ...
public TextBoxWithLabel()
{
DefaultStyleKey = typeof (TextBoxWithLabel);
}
}
I then have the current generic.xaml, which doesnt work, but it gives in idea of what i want:
<ResourceDictionary>
<ControlTemplate x:Key="ValueBoxWithLabelTemplate">
<StackPanel Style="{StaticResource ValueBoxWithLabelPanelStyle}">
<TextBlock Style="{StaticResource LabelStyle}" Text="{TemplateBinding LabelText}" />
<Grid>
<ContentPresenter Content="{TemplateBinding Content}" />
<local:DoubleClickButton Background="Black" x:Name="GoToEditModeButtonPart"></local:DoubleClickButton>
</Grid>
</StackPanel>
</ControlTemplate>
<Style TargetType="local:ValueBoxWithLabel">
<Setter Property="Template" Value="{StaticResource ValueBoxWithLabelTemplate}" />
</Style>
<Style TargetType="local:TextBoxWithLabel">
<Setter Property="Template" Value="{StaticResource ValueBoxWithLabelTemplate}" />
<Setter Property="Content">
<Setter.Value>
<TextBox Style="{StaticResource ValueBoxStyle}" Text="{TemplateBinding Text}" />
</Setter.Value>
</Setter>
</Style>
Since a ValueBoxWithLabel is most used with a TextBox i want to make a control for this, which reuses the same template, so i dont need to copy/paste the template, and have the headace of keeping both up-to-date with the same changes.
How can i reuse the ValueBoxWithLabelTemplate and only override the content property keeping the rest of the template?