Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Excessive flashing with flow document

 
 
Old 03-14-2008   #1 (permalink)
nickdu


 
 

Excessive flashing with flow document

I'm new to wpf so I'm not sure if my comment is valid. I'm playing with a
table control which I have housed in a flow document. In page mode or two
page mode when I'm not on the first page the background is redrawn (producing
a flashing effect) when data in the table has changed. Page 1 in both modes
does not exhibit this behavior. I would think the same logic could have been
done for subsequent pages. In case you need the code for my example, here it
is:

using System;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Controls;
using System.Threading;
using System.Collections;
using System.Collections.Generic;

public class Cell
{
private int _row;
private int _column;
private object _value;

public Cell(int row, int column, object value)
{
this._row = row;
this._column = column;
this._value = value;
}

public int Row
{
get
{
return this._row;
}
}

public int Column
{
get
{
return this._column;
}
}

public object Value
{
get
{
return this._value;
}
}
}

public class Application
{
private static Table _table = null;
private static EventWaitHandle _shutdown = null;
private delegate void UpdateTableEventHandler(ICollection<Cell> updates);

public static void DoUpdates()
{
int i;
int row;
int column;
int value;
Random random;
List<Cell> updates;
bool done;

random = new Random();
for (done = false; !done; )
{
updates = new List<Cell>();
for (i = 0; i < 200; i++)
{
row = random.Next(1000);
column = random.Next(3);
value = random.Next(1313);
updates.Add(new Cell(row, column, value));
}
Application._table.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.SystemIdle,
new UpdateTableEventHandler(Application.UpdateTable), updates);
if (Application._shutdown.WaitOne(100, false))
done = true;
}
}

static void UpdateTable(ICollection<Cell> updates)
{
foreach(Cell c in updates)
{
((IList)
Application._table.RowGroups[1].Rows[c.Row].Cells[c.Column].Blocks)[0] =
new Paragraph(new Run(c.Value.ToString()));
}
}

[STAThread]
public static void Main()
{
System.Windows.Application app;
TableRow row;
TableColumn column;
int i;
Thread dataProvider;
System.Threading.Timer timer;

Application._shutdown = new EventWaitHandle(false,
EventResetMode.ManualReset);
app = new System.Windows.Application();
app.MainWindow = new System.Windows.Window();
app.MainWindow.Content = new ScrollViewer();
Application._table = new Table();
((ScrollViewer) app.MainWindow.Content).Content = new FlowDocument();
((FlowDocument) ((ScrollViewer)
app.MainWindow.Content).Content).Blocks.Add(_table);
app.MainWindow.Show();

// Now modify the table.

column = new TableColumn();
column.Name = "FirstColumn";
_table.Columns.Add(column);
column = new TableColumn();
column.Name = "SecondColumn";
_table.Columns.Add(column);
column = new TableColumn();
column.Name = "ThirdColumn";
_table.Columns.Add(column);
_table.RowGroups.Add(new TableRowGroup());
_table.RowGroups[0].Rows.Add(new TableRow());
row = _table.RowGroups[0].Rows[0];
row.Background = Brushes.Silver;
row.FontSize = 20;
row.FontWeight = System.Windows.FontWeights.Bold;
row.Cells.Add(new TableCell(new Paragraph(new Run("First Column"))));
row.Cells.Add(new TableCell(new Paragraph(new Run("Second Column"))));
row.Cells.Add(new TableCell(new Paragraph(new Run("Third Column"))));
_table.RowGroups.Add(new TableRowGroup());
for (i = 0; i < 1000; ++i)
{
_table.RowGroups[1].Rows.Add(new TableRow());
row = _table.RowGroups[1].Rows[i];
row.Cells.Add(new TableCell(new Paragraph(new Run(string.Format("row {0}
column 1", i)))));
row.Cells.Add(new TableCell(new Paragraph(new Run(string.Format("row {0}
column 2", i)))));
row.Cells.Add(new TableCell(new Paragraph(new Run(string.Format("row {0}
column 3", i)))));
}


dataProvider = new Thread(new ThreadStart(DoUpdates));
dataProvider.Start();
// timer = new System.Threading.Timer(new TimerCallback(DoUpdates), null,
new TimeSpan(0, 0, 0, 20),
// new TimeSpan(0, 0, 0, 0, 3000));
app.Run();
Application._shutdown.Set();
dataProvider.Join();
}
}

--
Thanks,
Nick

nicknospamdu@xxxxxxam
remove "nospam" change community. to msn.com

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Money 2005 - Forecast Cash Flow Probs .NET General
Flashing windows border and flashing quick launch Vista General
control Flow items .NET General
Work Flow for an Image Restore? Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46