Skip to content

Instantly share code, notes, and snippets.

View deurell's full-sized avatar

Mikael Deurell deurell

View GitHub Profile
public class ColourCollectionViewModel
{
private readonly ColourCollectionModel _collectionModel;
private ObservableCollection<Color> _colours;
public ObservableCollection<Color> Colours
{
get { return _colours ?? (_colours = new ObservableCollection<Color>(_collectionModel.Colours)); }
}
<StackPanel>
<ItemsControl ItemsSource="{Binding .}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<views:ColourContainerView x:Name="ColourViewInstance"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<UserControl x:Class="ColourLab.views.ColourContainerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ColourLab="clr-namespace:ColourLab">
<Border BorderBrush="Black" BorderThickness="1" CornerRadius="2">
<StackPanel>
<TextBlock Text="{Binding Description}" Foreground="LightGray" />
<ColourLab:IndividualColourView/>
</StackPanel>
</Border>
<UserControl x:Class="ColourLab.IndividualColourView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="controlRoot">
<StackPanel>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="StackPanel.MouseEnter">
<BeginStoryboard Name="GoUp" HandoffBehavior="Compose">
<Storyboard>
<Int32Animation Storyboard.TargetName="controlRoot" Storyboard.TargetProperty="ColourWidth" To="100" Duration="0:0:0.6"
AccelerationRatio="0.1" DecelerationRatio="0.9" />
</Storyboard>
</BeginStoryboard>
// Validate fired event
[Test(Description = "Verify that prop changed fires [Mikael Deurell]")]
public void Description_Changed_FiresPropertyChanged()
{
// Given the user wants to change the product description on a Product
int notify = 0;
var sut = new ProductViewModel();
sut.PropertyChanged += (sender, e) =>
{
if (e.PropertyName.Equals("Description"))
// Fire Command
[Test(Description = "Added product shows up in repository with correct savestate")]
public void ExecutingCreateProductCommand_WithNewProduct_ShowsUpInRepository()
{
// Given the user wants to create a new product on the Create Product View
var product = new Product("4242", "desc", ProductType.Assortment, "201001", "123", _dummyArticles, null,
1);
// When the user clicks the New button a CreateProductCommand is fired on the ViewModel
var viewModel = new ProductViewModel(product);
// Fire command and validate mediator
[Test(Description = "Executing DisplayArticlesViewCommand sends message with products articles [Mikael Deurell]")]
public void Executing_DisplayArticlesViewCommand_SendsDisplayArticleViewListWithProvidedArticles()
{
// Given the user wants to display selected articles in a dialogue view
var sut =
new ProductViewModel(new Product("1", "desc", ProductType.Assortment, "10", "10", _dummyArticles, null,
0));
int notify = 0;
ObservableCollection<ArticleViewModel> articlesReceived = null;
public static IReadOnlyCollection<TItem> GetAllItems<TItem>(this IViewStorageReader viewStorage, string keyForListOfKeys, Logger logger, string typeOfItems, uint batchSize = 200)
where TItem : class
{
return GetAllItems<TItem, IEnumerable<string>>(viewStorage, keyForListOfKeys, logger, l => l.ToList(), typeOfItems, batchSize: batchSize);
}
@deurell
deurell / win10-convert.ps1
Last active August 29, 2015 14:20
project file conversion utility
# project file conversion utility
param (
[string]$folderPath = $(throw "-folderPath is required.")
)
$allProjectFiles = get-childitem -path $folderPath -Filter *.vcxproj -Recurse
foreach ($projectFile in $allProjectFiles){
$projectFileContent = get-content $projectFile.FullName
$projectFileContent |
@deurell
deurell / gist:10f4108d0aff5e97e70d
Created May 10, 2015 08:46
WinRT string conversion
std::wstring StringConverter::StringToWideString(const std::string& s) {
int len = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s.length(), NULL, 0);
std::wstring ws(L"", len);
wchar_t* pWSBuf = const_cast<wchar_t*>(ws.c_str());
MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, pWSBuf, len);
return ws;
}
std::string StringConverter::WideStringToString(const std::wstring& ws) {
int len = WideCharToMultiByte(CP_UTF8, 0, ws.c_str(), ws.length(), 0, 0, NULL, NULL);