Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带键盘的Windows phone 8和页眉_C#_.net_Xaml_Windows Phone 8_Windows Phone - Fatal编程技术网

C# 带键盘的Windows phone 8和页眉

C# 带键盘的Windows phone 8和页眉,c#,.net,xaml,windows-phone-8,windows-phone,C#,.net,Xaml,Windows Phone 8,Windows Phone,所以我有一个很大的问题: 在我的页面上(与微软的“消息应用程序”大致相同),当我点击输入框和键盘弹出窗口时,我的标题会向上移动,不再可见 我搜索了一点,发现大多数解决方案都不起作用(针对wp7…)。(就像一个博客,guy为Phoneframe创建了很多依赖属性,然后更改了边距。它可以工作一点,但在键盘动画期间标题会消失。这还不够,它真的不完美。) 微软在标准的“消息”应用程序中管理它(有一个字体大小变化的小错误),所以它一定是可能的 如何实现这一点?您可以将UI设置为listbox,以便滚动li

所以我有一个很大的问题:

在我的页面上(与微软的“消息应用程序”大致相同),当我点击输入框和键盘弹出窗口时,我的标题会向上移动,不再可见

我搜索了一点,发现大多数解决方案都不起作用(针对wp7…)。(就像一个博客,guy为Phoneframe创建了很多依赖属性,然后更改了边距。它可以工作一点,但在键盘动画期间标题会消失。这还不够,它真的不完美。)

微软在标准的“消息”应用程序中管理它(有一个字体大小变化的小错误),所以它一定是可能的


如何实现这一点?

您可以将UI设置为listbox,以便滚动listbox并检查向上的标题。

我尝试了此解决方案,效果很好:

  • 尝试收听
    TextBox.GotFocus
    TextBox.LostFocus
    事件,以检测应用程序中的文本框何时获取和释放焦点

  • 将您的全部内容放入
    ScrollViewer
    中,如下所示:

  • 代码XAML:

    <ScrollViewer x:Name="LayoutRoot" Margin="0,0,0,0">
        <Grid  Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
    
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
                <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
    
            <!--ContentPanel - place additional content here-->
            <Grid x:Name="ContentPanel" Grid.Row="1">
                <TextBox HorizontalAlignment="Left" Height="254" Margin="10,183,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="456" GotFocus="TextBox_GotFocus" LostFocus="TextBox_LostFocus"/>
            </Grid>
        </Grid>
    </ScrollViewer>
    
    事件:

    private void TextBox_GotFocus(object sender, RoutedEventArgs e)
    {
         LayoutRoot.Margin = new Thickness(0, 330, 0, 0);
         LayoutRoot.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
    }
    
    添加TextBox_LostFocus事件处理程序,以便在键盘关闭时将页面恢复到其原始视图:

    private void TextBox_LostFocus(object sender, RoutedEventArgs e)
    {
          LayoutRoot.Margin = new Thickness(0, 0, 0, 0);
          LayoutRoot.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
    }
    
    这有助于在打开键盘时将页面恢复到其原始位置。
    希望这有帮助。

    当呈现SIP键盘时,PhoneApplicationFrame.TranslateTransform.Y被设置为特定值(-259在横向方向,-339在纵向方向)。要更新布局,我们只需将顶部边距设置为指定的值(-s),然后Silverlight布局系统将修复该问题

    这里是XAML部分:

    <Grid x:Name="LayoutRoot" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0" Margin="12,17,0,28">
                <TextBlock Text="WINDOWS PHONE" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock Text="developer's ?" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
            <Grid Grid.Row="1" Margin="12,0,12,0"></Grid>
            <TextBox Grid.Row="2" LostFocus="TextBoxLostFocus"/>
        </Grid>
    
    
    
    C#份数

    private const double LandscapeShift=-259d;
    私人建筑双景观移位带=-328d;
    私有常数双ε=0.00000001d;
    私有常量双移位=-339d;
    私有常量双精度移位twithbar=-408d;
    public static readonly dependencProperty TranslateYProperty=dependencProperty.Register(“TranslateY”、typeof(double)、typeof(MainPage)、newpropertyMetadata(0d、OnRenderXPropertyChanged));
    公共主页()
    {
    初始化组件();
    加载+=主页加载;
    }
    公共双重翻译
    {
    获取{return(double)GetValue(TranslateYProperty);}
    set{SetValue(TranslateYProperty,value);}
    }
    私有静态无效OnRenderXPropertyChanged(DependencyObject d、DependencyPropertyChangedEventArgs e)
    {
    ((主页)d)UpdateTopMargin((双)e.NewValue);
    }
    private void MainPageLoaded(对象发送方,路由目标)
    {
    bindtokeboardfocus();
    }
    私有void bindtokeBoardFocus()
    {
    PhoneApplicationFrame=Application.Current.RootVisual作为PhoneApplicationFrame;
    如果(帧!=null)
    {
    var group=frame.RenderTransform作为TransformGroup;
    如果(组!=null)
    {
    var translate=group.Children[0]作为TranslateTransform;
    var translateYBinding=新绑定(“Y”);
    translateYBinding.Source=translate;
    设置绑定(TranslateYProperty,translateYBinding);
    }
    }
    }     
    私有void UpdateTopMargin(双translateY)
    {    
    if(IsClose(translateY,LandscapeShift)| | IsClose(translateY,肖像移位)| | IsClose(translateY,LandscapeShiftWithBar)| | IsClose(translateY,肖像移位WithBar))
    {
    LayoutRoot.Margin=新厚度(0,-translateY,0,0);
    }
    }
    私人厕所(双a,双b)
    {
    返回Math.Abs(a-b)
    您可以尝试以下链接。我想这会有帮助的


    虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,则仅链接的答案可能无效。
    <Grid x:Name="LayoutRoot" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0" Margin="12,17,0,28">
                <TextBlock Text="WINDOWS PHONE" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock Text="developer's ?" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
            <Grid Grid.Row="1" Margin="12,0,12,0"></Grid>
            <TextBox Grid.Row="2" LostFocus="TextBoxLostFocus"/>
        </Grid>
    
        private const double LandscapeShift = -259d;
        private const double LandscapeShiftWithBar = -328d;
        private const double Epsilon = 0.00000001d;
        private const double PortraitShift = -339d;
        private const double PortraitShiftWithBar = -408d;
    
        public static readonly DependencyProperty TranslateYProperty = DependencyProperty.Register("TranslateY", typeof(double), typeof(MainPage), new PropertyMetadata(0d, OnRenderXPropertyChanged));
    
        public MainPage()
        {
            InitializeComponent();
            Loaded += MainPageLoaded;
        }
    
        public double TranslateY
        {
            get { return (double)GetValue(TranslateYProperty); }
            set { SetValue(TranslateYProperty, value); }
        }
    
        private static void OnRenderXPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((MainPage)d).UpdateTopMargin((double)e.NewValue);
        }
    
        private void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            BindToKeyboardFocus();
        }
    
        private void BindToKeyboardFocus()
        {
            PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
            if (frame != null)
            {
                var group = frame.RenderTransform as TransformGroup;
                if (group != null)
                {
                    var translate = group.Children[0] as TranslateTransform;
                    var translateYBinding = new Binding("Y");
                    translateYBinding.Source = translate;
                    SetBinding(TranslateYProperty, translateYBinding);     
                }
            }
        }     
        private void UpdateTopMargin(double translateY)
        {    
          if(IsClose(translateY, LandscapeShift) || IsClose(translateY,PortraitShift) || IsClose(translateY, LandscapeShiftWithBar) || IsClose(translateY, PortraitShiftWithBar))
          {
            LayoutRoot.Margin = new Thickness(0, -translateY, 0, 0);  
          }
        }
    
        private bool IsClose(double a, double b)
        {
            return Math.Abs(a - b) < Epsilon;
        }
    
        private void TextBoxLostFocus(object sender, RoutedEventArgs e)
        {
            LayoutRoot.Margin = new Thickness();
        }