Irving r
Irving r

Reputation: 108

Silverlight, when rotating textbox not all the text shows

I have a custom control an inside of it I have a textbox that rotates depending wether you'd like it to collapse or expand, when it is collapsed I want the textbox to be vertical and when it is expanded I want it horizontal.

The problem is that when it is vertical the textbox doesn't show all the text, I've being looking for an answer, and I understand it has to do with the way silverlight updates it's layout. Here is my code

private void CollapseControl()
{
    CollapseCommand.Content = "E";            
    CollapseCommand.Margin = _btnMarginOnCollapse;

    BtnZoomIn.Visibility = Visibility.Collapsed;
    BtnZoomOut.Visibility = Visibility.Collapsed;
    ScrollViewerStackPanel.Visibility = Visibility.Collapsed;
    ZoomPanel.Visibility = Visibility.Collapsed;

    this.HorizontalAlignment = HorizontalAlignment.Left;
    this.Width = 40;

    RotateTransform nameRotateTransform = new RotateTransform();
    nameRotateTransform.Angle = 270;            
    Nametb.RenderTransform = nameRotateTransform;            
    Nametb.VerticalAlignment = VerticalAlignment.Bottom;
    Nametb.Height = Nametb.Width;
    Nametb.Width = Nametb.Height;
    Nametb.UpdateLayout();

}

Upvotes: 2

Views: 1423

Answers (3)

Shiv Kumar
Shiv Kumar

Reputation: 31

I just written following and my similar problem is solved.

layoutTransform.VerticalAlignment = VerticalAlignment.Bottom;
layoutTransform.VerticalAlignment = VerticalAlignment.Center;

Upvotes: 0

Spazmoose
Spazmoose

Reputation: 304

I just recently ran into a similar problem, and came up with the following solution (based on a post on the Silverlight forums), which should help with your issue, too:

private void CollapseControl()
{
    CollapseCommand.Content = "E";
    CollapseCommand.Margin = _btnMarginOnCollapse;

    BtnZoomIn.Visibility = Visibility.Collapsed;
    BtnZoomOut.Visibility = Visibility.Collapsed;
    ScrollViewerStackPanel.Visibility = Visibility.Collapsed;
    ZoomPanel.Visibility = Visibility.Collapsed;

    this.HorizontalAlignment = HorizontalAlignment.Left;

    LayoutTransform lt = new LayoutTransform();
    lt.Content = Nametb;

    RotateTransform nameRotateTransform = new RotateTransform();
    nameRotateTransform.Angle = 270;

    lt.LayoutTransform = nameRotateTransform;
    lt.ApplyLayoutTransform();
    Nametb.UpdateLayout();
}

Upvotes: 0

AnthonyWJones
AnthonyWJones

Reputation: 189555

One solution would be to use the LayoutTransformer control from the Silverlight toolkit.

You wrap the existing textblock inside a LayoutTransformer

        <toolkit:LayoutTransformer x:Name="Namelt" ...>
            <toolkit:LayoutTransformer.LayoutTransform>
                <RotateTransform />
            </toolkit:LayoutTransformer.LayoutTransform>
            <TextBlock x:Name="Nametb" Text="Hello World" />
        </toolkit:LayoutTransformer>

Then your code looks like:-

((RotateTransform)Namelt.LayoutTransform).Angle = 270;                         
Namelt.VerticalAlignment = VerticalAlignment.Bottom;     
Namelt.Height = Nametb.Width;     
Namelt.Width = Nametb.Height;  

Upvotes: 3

Related Questions