I have added the following code..
Step 1:-
---------------
public class MyTextBlock:Control
{
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(MyTextBlock), null);
public MyTextBlock()
{
DefaultStyleKey = typeof(MyTextBlock);
}
TextBlock innerTB;
public override void OnApplyTemplate()
{
innerTB = GetTemplateChild("textblock1") as TextBlock;
}
// set layout logic by handling MeasureOverride/ArrangeOverride.
protected override Size ArrangeOverride(Size finalSize)
{
return base.ArrangeOverride(finalSize);
}
protected override Size MeasureOverride(Size availableSize)
{
return base.MeasureOverride(availableSize);
}
}
Step2:-
------------
generic.xaml
----------------
<Style TargetType="my:MyTextBlock">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="my:MyTextBlock">
<TextBlock Name="textblock1"
Foreground="{TemplateBinding Foreground}"
FontSize="{TemplateBinding FontSize}"
Text="{TemplateBinding Text}"
/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
But When I keep the control in MainPage as
<my:MyTextBlock Text="My Text"/>
MyTextBlock is not visible in the browser. What is the problem I don't know.
We have created dependency property, template.... still we have this problem.
please help me. If possible can anyone test and if worked please attach the zip file.
Girish578, if this helps please login to Mark As Answer. | Alert Moderator