c# - Need help finishing or rewriting this algorithm for navigating a Generic Collection -
i trying come code algorithm set current object based on whether or not user clicks "forward" button or "backward" button.
public step currentstep { { return _currentstep; } set { if (_currentstep != value) { _currentstep = value; onpropertychanged("currentstep"); } } } private int currentstepindex { get; set; } private void nextstep() { currentstepindex++; gotostep(); } private void previousstep() { currentstepindex--; gotostep(); } private void gotostep() { var query = step in currentphase.steps ???? select step; currentstep = query.first(); }
currentphase.steps
observablecollection<step> steps {get; set;}
. , in constructor class have means of setting default value property "currentstep
" there 1 spring-board off of.
given collection hoping use index of currentstep
object stored in currentstepindex
go find item in collection , change index decrementing or incrementing it. then, using sort of linq query, go find "next step" @ new index.
unfortunately having hard time formulating linq query. what's more, not sure if algorithm going work.
what need complete linq query algorithm works?
or, there better way of achieving want?
it not necessary use linq here. observablecollection<t> inherits collection<t> has items property (indexer in c#). meanse can use following code instead of linq:
private void gotostep() { currentstep = currentphase.steps[currentstepindex]; }
Comments
Post a Comment