首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RenderTransform闪烁

RenderTransform闪烁
EN

Stack Overflow用户
提问于 2010-10-23 01:49:43
回答 1查看 606关注 0票数 2

请看下面的代码,在我单击按钮之后,列表框呈现了几次。如何防止列表框闪烁?可以告诉控件停止更新/渲染吗?

代码语言:javascript
复制
<UserControl x:Class="SilverlightApplication52.MainPage"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         d:DesignHeight="300"
         d:DesignWidth="400">

<Grid x:Name="LayoutRoot"
      Background="Gray"
      HorizontalAlignment="Stretch"
      VerticalAlignment="Stretch">
    <ListBox x:Name="listbox"
             Background="White"
             Margin="100">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">

            </Style>
        </ListBox.ItemContainerStyle>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Rectangle Width="{Binding Width}"
                           Height="{Binding Height}"
                           Fill="{Binding Background}"
                           RenderTransformOrigin="0.5,0.5">
                    <Rectangle.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform ScaleX="{Binding Scale}"
                                            ScaleY="{Binding Scale}" />
                            <RotateTransform Angle="{Binding Angle}" />
                            <TranslateTransform X="{Binding Left}"
                                                Y="{Binding Top}" />
                        </TransformGroup>
                    </Rectangle.RenderTransform>
                </Rectangle>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    <Button Content="test"
            Width="50"
            Height="50"
            Click="Button_Click" />
</Grid>

代码语言:javascript
复制
public partial class MainPage : UserControl
{
    public class ItemInfo
    {
        public double Left { get; set; }
        public double Top { get; set; }
        public double Width { get; set; }
        public double Height { get; set; }
        public double Angle { get; set; }
        public double Scale { get; set; }
        public Brush Background { get; set; }
    }

    ObservableCollection<ItemInfo> _items = new ObservableCollection<ItemInfo>();
    public MainPage()
    {
        InitializeComponent();
        listbox.ItemsSource = _items;

    }

    Random random = new Random();
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        _items.Clear();
        for (int i = 0; i < 2000; i++)
        {
            byte r = (byte)(random.NextDouble()*255);
            byte g = (byte)(random.NextDouble()*255);
            byte b = (byte)(random.NextDouble()*255);
            _items.Add(
                new ItemInfo
                {
                    Left = random.NextDouble() * 500,
                    Top = random.NextDouble() * 500,
                    Width = random.NextDouble() * 1000,
                    Height = random.NextDouble() * 1000,
                    Angle = random.NextDouble() * 359,
                    Scale = random.NextDouble() * 1,
                    Background = new SolidColorBrush(Color.FromArgb(255,r,g,b)),
                }
            );
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2010-10-23 06:03:35

尝试添加到该循环中的单独ObservableCollection (未引用/绑定到列表框)。然后,当循环完成时,将列表框ItemsSource赋值给新的可观察集合。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3999534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档