Skip to content

Instantly share code, notes, and snippets.

List<string> countries = {"Argentina", "Australia", "Belgium", "Chile", "Denmark", "Fiji", "Germany", "Greece"};
var newList = from c in countries
where c.Contains("e")
select c.ToUpper();
x => /*some code goes here*/
// Some data to work with
List<string> countries = {"Argentina", "Australia", "Belgium", "Chile", "Denmark", "Fiji", "Germany", "Greece"};
// Using a foreach loop
var newList = new List<string>();
foreach(var c in countries)
{
if (c.Contains("e"))
{
newList.Add(c);
// Some data to work with
List<string> countries = {"Argentina", "Australia", "Belgium", "Chile", "Denmark", "Fiji", "Germany", "Greece"};
// Using a foreach loop
var filteredList = new List<string>();
foreach(var c in countries)
{
if (c.Contains("e"))
{
filteredList.Add(c);
<ListView>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
protected override Size MeasureOverride(Size availableSize)
{
// Set it to use whole available width
var finalSize = new Size { Width = availableSize.Width };
var columnWidth = availableSize.Width / MaximumColumns;
var rowHeight = 0d;
var rowChildCount = 0;
foreach (var child in Children)
{
protected override Size ArrangeOverride(Size finalSize)
{
var columnWidth = finalSize.Width / MaximumColumns;
var posY = 0d;
var rowHeight = 0d;
var rowChildCount = 0;
foreach (var child in Children)
{
if (rowChildCount >= MaximumColumns)
@jonstodle
jonstodle / UniformWidthWrapPanel.cs
Last active April 13, 2019 21:48
A panel which arranges it's children into the specified amount of columns and stretches them to uniformly consume the whole width
using System;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace KodeFisk
{
public class UniformWidthWrapPanel : Panel
{
public UniformWidthWrapPanel()
@jonstodle
jonstodle / AutoUniformWidthWrapPanel.cs
Created October 29, 2015 18:54
A panel which arranges as many children as possible into one row and stretches them to uniformly consume the whole width
using System;
using System.Collections.Generic;
using System.Linq;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace KodeFisk
{
public class AutoUniformWidthWrapPanel : Panel