Feasibility of creating a Timeline control using Grid
I want to create a timeline WPF control (as in this (http://www.taterboy.com/blog/images/MotionEditor/classic_vs_custom.png) kind of timeline - for animation editing).
I prototyped a simple Winforms control like this by drawing everything manually in a PaintEvent handler, and though it worked and was probably the most efficient way it wasn't flexible or attractive.
I am making a fully featured control using WPF, and wondered about the possibility of using a Grid control as the timeline - each discrete time position represented by a column (shaded when a keyframe is present) and tracks by the rows.
I don't though, know anything about this control, and this is the first time ive used WPF so I was wondering if anyone could comment on this idea?
Specifically, from a performance standpoint, is the g开发者_StackOverflow社区rid designed to be used this way or is it more for structuring a gui at design time? Will I incur a serious performance penalty trying to modify its configuration dynamically, with a large number of elements? (~2000-3000 would be a likely worst case)
From a coding standpoint, how easy is it to modify the grid? And to do things like shading the cells for example? Is it a simple matter of Grid.NumberOfColumns = x
or must every element be a unique object?
Thanks for any insights!
Using a Grid
is certainly an option and working with the Grid
within XAML and code behind is fairly trivial.
<Grid Name="MyGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
</Grid>
MyGrid.ColumnDefinitions.Add(new ColumnDefinition()
{ Width = new GridLength(0, GridUnitType.Star) });
You could then use a Rectangle
to take care of your shading.
<Rectangle Grid.Column="0"></Rectangle>
The problem will come down to performance however you may be able to get by depending on a variety of factors. If the performance is a hinderance a different approach may be to use a VirtualizingStackPanel as the underlying layout container within an ItemsControl as it will address UI virtualization. Data virtualization could also become an issue and should be addressed after UI vritualization via the VirtualizingStackPanel
. The ItemsControl
will allow you to provide a DataTemplate for items and should be a better approach in the long run to using the Grid
based on your initial statement with regard to the size.
Expression Blend was built using WPF and has extensive support for animation; including an interactive and robust timeline, so it can be done. Understanding WPF is the key otherwise you will end up refactoring your initial approach as your understanding grows. Try, if you can, to get a decent foundation on how WPF differs from WinForms (it is drastic) as it will make your life easier down the road.
精彩评论