在WP7滚动文本框(ALA的Skype和Facebook) [英] Scrollable TextBox in WP7 (ala Skype and Facebook)

查看:134
本文介绍了在WP7滚动文本框(ALA的Skype和Facebook)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我正在开发一个记笔记的应用程序,用户可以只要他想(有点像的在WP7 滚动文本框)。我把文本框在一个ScrollViewer中,并且一切都很好;我禁用的ScrollViewer当文本框获得焦点,所以当用户键入自动滚动。

Basically, I'm developing a note-taking app where the user can type as long as he wants (kinda like Scrollable TextBox in WP7). I put the TextBox in a ScrollViewer, and everything is fine; I disable the ScrollViewer when the TextBox gets focus, so it scrolls automatically while the user is typing.

我的问题是,我希望用户能够滚动,而编辑音符,就像他能够在阅读笔记滚动。我认为这样做会直到出现过大的插入符号,然后移动它按住的唯一途径,但我发现,其实,第三方应用程序支持这种类型的滚动的。

My problem is, I want the user to be able to scroll while editing the note, just as he's able to scroll while reading the note. I thought the only way to do this would be to hold down until the oversized caret appears, then moving it around, but I discovered that, in fact, third party apps support this type of scrolling.

我试图做到的,是像手机,其中在编辑文档(的这里的展示它的视频)。同样的效果是出现在Skype和Facebook应用的地方,一边写邮件时,你可以滚动它,看多了吧。

What I'm trying to achieve is something like Word/OneNote on the phone, where the user can easily scroll while editing the document (here's a video demonstrating it). The same effect is seen in the Skype and Facebook apps where, while writing a message, you can scroll it to see more of it.

我不知道这是一个自定义控制,或者如果布局被设计在一个特定的方式,因为里面的ScrollViewer一个TextBox根本不起作用。

I wonder if this is a custom control, or if the layout was designed in a specific way, because a TextBox inside a ScrollViewer simply doesn't work.

我会很感激的任何帮助。先谢谢了。

I'd appreciate any help. Thanks in advance.

推荐答案

根据由Ku6opr给出了答案,我调整了代码,所以它的作品在我的情况。现在,文本框有定期的行为,而是滚动的,而RootFrame不会自动上去

Based on the answer given by Ku6opr, I tweaked the code so it works under my circumstances. Now, the TextBox has regular behavior, but is scrollable, and the RootFrame doesn't go up automatically.

XAML:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <ScrollViewer x:Name="InputScrollViewer">
        <TextBox x:Name="MessageText" TextWrapping="Wrap" Text="" AcceptsReturn="True" TextChanged="inputText_TextChanged" GotFocus="MessageText_GotFocus" Padding="0,0,0,400" Tap="MessageText_Tap" />
    </ScrollViewer>
</Grid>



C#:

C#:

public partial class MainPage : PhoneApplicationPage
{
    double InputHeight = 0.0;

    // Constructor
    public MainPage()
    {
        InitializeComponent();
    }

    private void MessageText_GotFocus(object sender, System.Windows.RoutedEventArgs e)
    {
        (App.Current as App).RootFrame.RenderTransform = new CompositeTransform();
    }

    private void inputText_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
    {
        Dispatcher.BeginInvoke(() =>
        {
            double CurrentInputHeight = MessageText.ActualHeight;

            if (CurrentInputHeight > InputHeight)
            {
                InputScrollViewer.ScrollToVerticalOffset(InputScrollViewer.VerticalOffset + CurrentInputHeight - InputHeight);
            }

            InputHeight = CurrentInputHeight;
        });
    }

    public void MessageText_Tap(object sender, GestureEventArgs e)
    {
        InputScrollViewer.ScrollToVerticalOffset(e.GetPosition(MessageText).Y - 80);
    }
}



点击事件处理程序检测到自来水的垂直位置和滚动的ScrollViewer使插入符是视图时文本框获得焦点。

The Tap event handlers detects the vertical position of the tap, and scrolls the ScrollViewer so the caret is in view when the TextBox gets focus.

这篇关于在WP7滚动文本框(ALA的Skype和Facebook)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆