in my WPF application i used to add controls dynamically to a Canvas. The name format of the control is "Control_UniqueValue".
i.e., if i add first control to the canvas, then the name will be "Control_1" and the next will be "Control_2" etc...
my requirement is to get the max value of the added controls
i used the following statement for that
string maxId = (string)canvas1.Children.Cast<FrameworkElement>().ToList().Max(x => (x.Name.Substring(x.Name.LastIndexOf('_') + 1)));
but the problem here is
need to return the value as int
if the canvas contains no controls it will raise error (tried using
Nullabletype, but failed)