Silverlight,旋转文本框时并非所有文本都显示

发布于 2024-12-14 06:40:00 字数 935 浏览 3 评论 0原文

我有一个自定义控件,其中有一个文本框,可以旋转,具体取决于您希望它折叠还是展开,当它折叠时,我希望文本框是垂直的,当它展开时,我希望它水平。

问题是,当它是垂直的时,文本框不会显示所有文本,我一直在寻找答案,并且我知道这与 silverlight 更新其布局的方式有关。这是我的代码

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();

}

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();

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

送君千里 2024-12-21 06:40:00

一种解决方案是使用 Silverlight 工具包LayoutTransformer 控件>。

您将现有的文本块包装在 LayoutTransformer

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

然后您的代码如下所示:-

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

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;  
执笏见 2024-12-21 06:40:00

我最近遇到了类似的问题,并提出了以下解决方案(基于 Silverlight 论坛上的帖子),这也应该有助于解决您的问题:

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();
}

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();
}
从来不烧饼 2024-12-21 06:40:00

我刚刚写了以下内容,我的类似问题就解决了。

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

I just written following and my similar problem is solved.

layoutTransform.VerticalAlignment = VerticalAlignment.Bottom;
layoutTransform.VerticalAlignment = VerticalAlignment.Center;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文