当前位置: 首页>>代码示例>>C#>>正文


C# Grid.UpdateLayout方法代码示例

本文整理汇总了C#中Windows.UI.Xaml.Controls.Grid.UpdateLayout方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.UpdateLayout方法的具体用法?C# Grid.UpdateLayout怎么用?C# Grid.UpdateLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.UI.Xaml.Controls.Grid的用法示例。


在下文中一共展示了Grid.UpdateLayout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddGunDanmu

        /// <summary>
        /// 添加滚动弹幕
        /// </summary>
        /// <param name="model">弹幕参数</param>
        /// <param name="Myself">是否自己发送的</param>
        public async void AddGunDanmu(DanMuModel model,bool Myself)
        {
            try
            {
                
                //创建基础控件
                TextBlock tx = new TextBlock();
                TextBlock tx2 = new TextBlock();
                Grid grid = new Grid();
                //设置控件相关信息
                grid.Margin = new Thickness(0, 0, 20, 0);
                grid.VerticalAlignment = VerticalAlignment.Center;
                grid.HorizontalAlignment = HorizontalAlignment.Left;
                if (fontFamily != "默认")
                {
                    tx.FontFamily = new FontFamily(fontFamily);
                    tx2.FontFamily = new FontFamily(fontFamily);
                }
                tx2.Text = model.DanText;
                tx.Text = model.DanText;
                tx2.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                tx.Foreground = model.DanColor;
                //弹幕大小
                double size = double.Parse(model.DanSize);
                if (size == 25)
                {
                    tx2.FontSize = fontSize;
                    tx.FontSize = fontSize;
                }
                else
                {
                    tx2.FontSize = fontSize - 2;
                    tx.FontSize = fontSize - 2;
                }

                //grid包含弹幕文本信息
                grid.Children.Add(tx2);
                grid.Children.Add(tx);
                grid.VerticalAlignment = VerticalAlignment.Top;
                grid.HorizontalAlignment = HorizontalAlignment.Left;

                TranslateTransform moveTransform = new TranslateTransform();
                moveTransform.X = grid_Danmu.ActualWidth;
                grid.RenderTransform = moveTransform;
                //将弹幕加载入控件中,并且设置位置
                grid_Danmu.Children.Add(grid);
                Grid.SetRow(grid, row);
                row++;
                if (row == maxRow)
                {
                    row = 0;
                }
                tx2.Margin = new Thickness(1);
                if (Myself)
                {
                    grid.BorderThickness = new Thickness(2);
                    grid.BorderBrush = new SolidColorBrush(Colors.Gray);
                }
                grid.Opacity = Tran;
                grid.DataContext = model;
                //更新弹幕UI,不更新无法获得弹幕的ActualWidth
                grid.UpdateLayout();
                //创建动画
                Duration duration = new Duration(TimeSpan.FromSeconds(Speed));
                DoubleAnimation myDoubleAnimationX = new DoubleAnimation();
                myDoubleAnimationX.Duration = duration;
                //创建故事版
                Storyboard justintimeStoryboard = new Storyboard();
                justintimeStoryboard.Duration = duration;
                myDoubleAnimationX.To = -(grid.ActualWidth);//到达
                justintimeStoryboard.Children.Add(myDoubleAnimationX);
                Storyboard.SetTarget(myDoubleAnimationX, moveTransform);
                //故事版加入动画
                Storyboard.SetTargetProperty(myDoubleAnimationX, "X");
                grid_Danmu.Resources.Remove("justintimeStoryboard");
                grid_Danmu.Resources.Add("justintimeStoryboard", justintimeStoryboard);
                justintimeStoryboard.Begin();
                //等待,暂停则暂停
                await Task.Run(async () =>
                {
                    int i = 0;
                    while (true)
                    {
                        if (!IsPlaying)
                        {
                            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                                justintimeStoryboard.Pause();
                            });
                            //break;
                        }
                        else
                        {
                            if (i == Speed*2)
                            {
                                break;
//.........这里部分代码省略.........
开发者ID:GeminiLab,项目名称:BiliBili-UWP,代码行数:101,代码来源:MyDanmaku.xaml.cs

示例2: InitializeFoodsAndFacilitiesLayout

        public void InitializeFoodsAndFacilitiesLayout()
        {
            if (Children == null) return;
            if (Children.Count < 2) return;

            try
            {
                _mainFragment = Children.OfType<Grid>().FirstOrDefault();
                _listFragment = Children.OfType<Grid>().ElementAt(1);
            }
            catch
            {
                return;
            }

            if (_mainFragment == null || _listFragment == null) return;

            _mainFragment.Name = "_mainFragment";
            _listFragment.Name = "_listFragment";

            // _mainFragment
            _mainFragment.HorizontalAlignment = HorizontalAlignment.Stretch;
            _mainFragment.VerticalAlignment = VerticalAlignment.Stretch;
            if (_mainFragment.Background == null) _mainFragment.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));

            // Render transform _listFragment
            _listFragment.HorizontalAlignment = HorizontalAlignment.Left;
            _listFragment.VerticalAlignment = VerticalAlignment.Stretch;
            _listFragment.Width = (Window.Current.Bounds.Width/3)*2;
            if (_listFragment.Background == null) _listFragment.Background = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));

            var animatedTranslateTransform = new TranslateTransform {X = -_listFragment.Width, Y = 0};

            _listFragment.RenderTransform = animatedTranslateTransform;
            _listFragment.RenderTransformOrigin = new Point(0.5, 0.5);

            _listFragment.UpdateLayout();

            // Create a shadow element
            _shadowFragment = new Grid
            {
                Name = "_shadowFragment",
                Background = new SolidColorBrush(Color.FromArgb(0, 255, 255, 255)),
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Visibility = Visibility.Collapsed
            };
            _shadowFragment.Tapped += shadowFragment_Tapped;
            _shadowFragment.IsHitTestVisible = false;

            // Set ZIndexes
            Canvas.SetZIndex(_shadowFragment, 50);
            Canvas.SetZIndex(_listFragment, 51);
            Children.Add(_shadowFragment);

            // Create a new fadeIn animation storyboard
            _fadeInStoryboard = new Storyboard();

            // New double animation
            var doubleAnimation1 = new DoubleAnimation {Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)), To = 0};

            Storyboard.SetTarget(doubleAnimation1, _listFragment);
            Storyboard.SetTargetProperty(doubleAnimation1, TranslatePath.Path);
            _fadeInStoryboard.Children.Add(doubleAnimation1);

            // New color animation for _shadowFragment
            var colorAnimation1 = new ColorAnimation
            {
                Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)),
                To = Color.FromArgb(190, 0, 0, 0)
            };

            Storyboard.SetTarget(colorAnimation1, _shadowFragment);
            Storyboard.SetTargetProperty(colorAnimation1,ColorPath.Path);
            _fadeInStoryboard.Children.Add(colorAnimation1);

            // Create a new fadeOut animation storyboard
            _fadeOutStoryboard = new Storyboard();

            // New double animation
            var doubleAnimation2 = new DoubleAnimation
            {
                Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)),
                To = -_listFragment.Width
            };

            Storyboard.SetTarget(doubleAnimation2, _listFragment);
            Storyboard.SetTargetProperty(doubleAnimation2, TranslatePath.Path);
            _fadeOutStoryboard.Children.Add(doubleAnimation2);

            // New color animation for _shadowFragment
            var colorAnimation2 = new ColorAnimation
            {
                Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)),
                To = Color.FromArgb(0, 0, 0, 0)
            };

            Storyboard.SetTarget(colorAnimation2, _shadowFragment);
            Storyboard.SetTargetProperty(colorAnimation2, ColorPath.Path);
            _fadeOutStoryboard.Children.Add(colorAnimation2);
//.........这里部分代码省略.........
开发者ID:RajaRajendraprasath,项目名称:FoodsAndFacilities,代码行数:101,代码来源:FoodsAndFacilitiesLayout.cs

示例3: AddTopButtomDanmu

        private bool Handling = false;//是否正在监听
        /// <summary>
        /// 添加顶部及底部弹幕
        /// </summary>
        /// <param name="model">弹幕参数</param>
        /// <param name="istop">是否顶部</param>
        /// <param name="Myself">是否自己发送的</param>
        public async void AddTopButtomDanmu(DanMuModel model, bool istop,bool Myself)
        {
            TextBlock tx = new TextBlock();
            TextBlock tx2 = new TextBlock();
            Grid grid = new Grid();
            if (fontFamily != "默认")
            {
                tx.FontFamily = new FontFamily(fontFamily);
                tx2.FontFamily = new FontFamily(fontFamily);
            }

                tx2.Text =model.DanText;
                tx.Text = model.DanText ;
            tx2.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
            tx.Foreground = model.DanColor;//new SolidColorBrush(co[rd.Next(0, 7)]);
            double size = double.Parse(model.DanSize);
            if (size == 25)
            {
                tx2.FontSize = fontSize;
                tx.FontSize = fontSize;
            }
            else
            {
                tx2.FontSize = fontSize - 2;
                tx.FontSize = fontSize - 2;
            }
            //grid包含弹幕文本信息
            grid.Children.Add(tx2);
            grid.Children.Add(tx);

            // tx.FontSize = Double.Parse(model.DanSize) - fontSize;
            grid.HorizontalAlignment = HorizontalAlignment.Center;
            grid.VerticalAlignment = VerticalAlignment.Top;
            tx2.Margin = new Thickness(1);
            if (Myself)
            {
                grid.BorderThickness = new Thickness(2);
                grid.BorderBrush = new SolidColorBrush(Colors.Gray);
            }
            grid.Opacity = Tran;
            grid.DataContext = model;
            grid.UpdateLayout();

            if (istop)
            {
                D_Top.Children.Add(grid);
                await Task.Delay(5000);
                if (state== MediaElementState.Paused)
                {
                    ClearTopButtomDanmuku();
                }
                else
                {
                    D_Top.Children.Remove(grid);
                }
            }
            else
            {
                D_Bottom.Children.Add(grid);
                await Task.Delay(5000);
                if (state == MediaElementState.Paused)
                {
                    ClearTopButtomDanmuku();
                }
                else
                {
                    D_Bottom.Children.Remove(grid);
                }
            }
        }
开发者ID:GeminiLab,项目名称:BiliBili-UWP,代码行数:77,代码来源:MyDanmaku.xaml.cs


注:本文中的Windows.UI.Xaml.Controls.Grid.UpdateLayout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。