本文整理匯總了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;
//.........這裏部分代碼省略.........
示例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);
//.........這裏部分代碼省略.........
示例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);
}
}
}