3

Writing an app for Windows Phone, I want to create custom control, inherited from TextBlock. But form of this control should be not rectangular. I tried to use Blend for this task, but I couldn't find properties to change form of controls.

desirable form of custom control

On the image above there is schematic form of control. I suppose, that there is possibility to set coordinates of angles of control, but I didn't find it. Thank you.

Max Zhukov
  • 877
  • 1
  • 8
  • 32

1 Answers1

2

This problem can be solved in several ways, I chose to use a Template with their figures. In the role of the figures will be performing standard Rectangles. Template for TextBlock can not be set, so I opted for a more universal control - Label.

Example:

<Style TargetType="{x:Type Label}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Label}">
                <Border Background="{TemplateBinding Background}">
                    <Grid>
                        <Rectangle Width="30" Height="70" Fill="Gainsboro" StrokeThickness="1" Margin="0,0,0,10" Panel.ZIndex="0" />
                        <ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="33,0,0,25" Panel.ZIndex="1" />
                        <Rectangle MinWidth="55" Height="30" StrokeThickness="1" Fill="Gainsboro" HorizontalAlignment="Left" Margin="30,30,0,0" />
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Declared Label in XAML:

<Label Background="Transparent" Width="200" Height="90" Content="Test your label" />

Output

enter image description here

Naturally, you will need to change the Template to fit your needs.

Note about several ways:

Community
  • 1
  • 1
Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
  • 1
    thank you! there is no Label control in windows phone, and class Decorator only is in WPF, but I'll rewrite you way. – Max Zhukov Jul 12 '13 at 23:51