Removing an item from a list without using a loop

  • Thread starter Thread starter matty1248
  • Start date Start date
M

matty1248

Guest
Hi,

I'm trying to build a class which can add and delete items from a list where there is no loop involved. It could be that I can add a loop but I don't see a means of doing so. Some of the classes called are UWP but the essence of the problem is in the C# code and no one over on UWP seems to have a solution.

The list ("TempOpenings") is instantiated as a property then added to within the virtual method "TrueOfBoth" in my code below. One of the UIElements creates a delete button every time the event in the using class is triggered, the function of the delete button is to remove the item from the list. The code condenses down a lot if you input it, i've emboldened all the relevant parts, and it is as follows:

using PanelWriter1._11.PhysicalAssemblies;
using System.Collections.Generic;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

namespace PanelWriter1._11.UIElements
{
public abstract class AbsOpeningControlModule
{
private Style style1 = Application.Current.Resources["TextBlockStyle"] as Style;
private Style style2 = Application.Current.Resources["ButtonSubPaneStyle"] as Style;
private IDictionary<string, Thickness> thicknes;

public Style Style1
{
get
{
return style1;
}
set
{
style1 = value;
}
}
public Style Style2
{
get
{
return style2;
}
set
{
style2 = value;
}
}

public RelativePanel RespPanel { get; set; }
public List<int> Temps { get; set; }
public List<int> DoorTemps { get; set; }
public List<int> WindowTemps { get; set; }
public List<OpeningMembers> TempOpenings { get; set; }
public int InputCHeight { get; set; }
public int InputHHeight { get; set; }
public int InputOWidth { get; set; }
public bool LintelCheck { get; set; }

public IDictionary<string, Thickness> Thicknes { get { return thicknes; } }

public ICollection<UIElement> OpeningInputRefModule;

public AbsOpeningControlModule(RelativePanel RespPanel, List<int> Temps, List<int> DoorTemps, List<int> WindowTemps, int InputCHeight, int InputHHeight, int InputOWidth, bool LintelCheck)
{
this.RespPanel = RespPanel;
this.Temps = Temps;
this.DoorTemps = DoorTemps;
this.WindowTemps = WindowTemps;
this.InputCHeight = InputCHeight;
this.InputHHeight = InputHHeight;
this.InputOWidth = InputOWidth;
this.LintelCheck = LintelCheck;
}

public abstract void TrueOfTemplates();
public abstract void TrueOfActual();

#region [Public methods]
public virtual void TrueOfBoth()
{

TempOpenings.Add(new OpeningMembers(InputOWidth, InputHHeight, InputCHeight, LintelCheck));

int BHO = 78 * (Temps.Count -1) + 4;
RespPanel.Background = new SolidColorBrush(Colors.DarkGray);

#region [opening codes]
string OpeningCode()
{
if (InputCHeight == 0)
{
if (LintelCheck == true)
{
string TypeCount = $"{DoorTemps.Count}";
string Specs = $"D{TypeCount}: With lintel";
return Specs;
}
else
{
string TypeCount = $"{DoorTemps.Count}";
string Specs = $"D{TypeCount}: No lintel";
return Specs;
}
}
else
{
if (LintelCheck == true)
{
string TypeCount = $"{WindowTemps.Count}";
string Specs = $"W{TypeCount}: Linteled";
return Specs;
}
else
{
string TypeCount = $"{WindowTemps.Count}";
string Specs = $"W{TypeCount}:";
return Specs;
}
}
}
string OpeningSpecs()
{
if (InputCHeight == 0)
{
string Specs = $"W: {InputOWidth} HH: {InputHHeight}";
return Specs;
}
else
{
string CillRequired = "CH: ";
string Specs = $"W: {InputOWidth} HH: {InputHHeight} {CillRequired}{InputCHeight}";
return Specs;
}
}
#endregion
#region[UIElements]
TextBlock openingCode = new TextBlock()
{ Margin = new Thickness(4, BHO, 0, 0), Text = OpeningCode(), Style = style1 };
//OpeningInputRefModule.Add(openingCode);
RespPanel.Children.Add(openingCode);

Button deleteOpening = new Button()
{ Margin = new Thickness(0, 4, 4, 0), Style = style2, Content = "DEL" };
deleteOpening.Click += deleteOpening_Click;
//OpeningInputRefModule.Add(deleteOpening);
RespPanel.Children.Add(deleteOpening);


TextBlock openingDescription = new TextBlock()
{ Margin = new Thickness(4, 4, 0, 0), Text = OpeningSpecs(), Style = style1 };
//OpeningInputRefModule.Add(openingDescription);
RespPanel.Children.Add(openingDescription);
#endregion

void deleteOpening_Click(object sender1, RoutedEventArgs e1)
{
TempOpenings.Remove();
}


#region [alignments]
RelativePanel.SetAlignTopWithPanel(openingCode, true);
RelativePanel.SetAlignLeftWithPanel(openingCode, true);
RelativePanel.SetBelow(deleteOpening, openingCode);
RelativePanel.SetAlignRightWithPanel(deleteOpening, true);
RelativePanel.SetAlignLeftWithPanel(openingDescription, true);
RelativePanel.SetAlignVerticalCenterWith(openingDescription, deleteOpening);
#endregion
}
#endregion
}
}

The part that I need to write is in the 'deleteOpening_Click' event. Any advice would be appreciated, I've been chasing this one around for about a month now and just can't seem to get to the bottom of it.

Cheers,

Matthew

Continue reading...
 
Back
Top