Home : Position texts before and and after a time item
Q11433 - FAQ: Position texts before and and after a time item

Question

Howto get textblocks to appear before and after the TimeItem?

Answer

In this time item the Grid with name Rect is the one that gets the size based on Start and Stop datetime values.

The Text after the time item is the one named Text1, the one infront is Text2.

Text1 is positioned in the event implementation: SizeChanged="TimeItem_SizeChanged" see impl at the bottom

Text2 is positioned with a Translate transform with a negative value.

        <DataTemplate x:Name="SquaredTimeItem">

            <l:TimeItem Height="20"

                Start="{Binding Start,Mode=TwoWay}"

                Stop="{Binding Stop,Mode=TwoWay}"

                Identity="{Binding Id}"

                TimeItemSizedFrameworkElementName="Rect" SizeChanged="TimeItem_SizeChanged">

 

                <Grid Height="20" Name="Rect">

                    <Border  BorderBrush="Black" BorderThickness="0" CornerRadius="3">

                        <Border.Background>

                            <LinearGradientBrush>

                                <LinearGradientBrush.GradientStops>

                                    <GradientStop Offset="0" Color="LightGray"/>

                                    <GradientStop Offset="1" Color="Gray"/>

                                </LinearGradientBrush.GradientStops>

                            </LinearGradientBrush>

                        </Border.Background>

                    </Border>

                </Grid>

                <TextBlock Name="Text1" HorizontalAlignment="Right" Margin="3,6,0,0" Text="{Binding To}" >

                            <TextBlock.RenderTransform>

                                <TranslateTransform X="20"></TranslateTransform>

                            </TextBlock.RenderTransform>

                </TextBlock>

                <TextBlock Name="Text2" HorizontalAlignment="Left" Margin="3,6,0,0" Text="{Binding From}" >                           

                            <TextBlock.RenderTransform>

                                <TranslateTransform X="-25"></TranslateTransform>

                            </TextBlock.RenderTransform>

                </TextBlock>

 

            </l:TimeItem>

        </DataTemplate>

 

        private void TimeItem_SizeChanged(object sender, SizeChangedEventArgs e)

        {

            if (sender is TimeItem)

            {

                TextBlock tb1=(sender as TimeItem).FindName("Text1") as TextBlock;

                (tb1.RenderTransform as TranslateTransform).X = e.NewSize.Width + 10;

            }

        }

 

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 2009-04-09.
Last Modified on 2009-04-09.
Last Modified by Administrator.
Article has been viewed 285 times.
Rated 0 out of 10 based on 0 votes.
Print Article
Email Article