Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Store Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems.

Go Back   Vista Forums > Vista technology newsgroups > Avalon

Excessive flashing with flow document

Reply
 
Thread Tools Display Modes
Old 03-14-2008   #1 (permalink)
nickdu
Guest
 
Posts: n/a

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
  Reply With Quote

Reply

Thread Tools
Display Modes









Vistax64.com 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 2005-2008

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 47 48