background preloader

TODO

Facebook Twitter

TIP: Make a WPF dialog/window as application modal. Technology News, Computer and Notebook Reviews, Computer News, Computer Mods, PC News | Maximum PC. How To Change WPF ListBox SelectedItem Color. WPF UserControl Scrollbar and resizing problem. A Two Column Grid for WPF. Download source and binaries - 24.3 KB Introduction Have you ever designed a screen where you have pairs of "Label: TextBox" in rows beneath each other? My guess is yes, since this UI is pretty much standard in every configuration window ever designed. My guess is also that while designing this, you got frustrated with having to define new rows all the time in the Grid. Wouldn't it be nice to combine the row/column layout of a grid with the simple no-need-to-define-anything style of the StackPanel? Read on and I'll show a custom panel that achieves this.

The Problem The Grid in WPF is extremely powerful and can achieve pretty much any layout thinkable. What's worse is that if you want to move stuff around (or add things in the middle), you have to update all the Grid.Column="x" and Grid.Row="y" entries manually. The Solution Let's instead define a custom panel which has these properties: No row/column definitions. As for column sizing, we define the following: The Code Measuring the Children. Wpf - Setting focus on a ListBox item breaks keyboard navigation. WPF Tutorial | Selected Item Background. If you select an item in a listbox it gets the default selection color (usually blue) as background. Even if you specify a custom data template. The reason is that the blue background (or gray if the control is not focussed) is drawn outside of the data template. So you have no chance to override it from within the data template.

The color used to draw the blue and gray background are system colors. So the easiest way to get rid of these backgrounds is to locally override the highlight and control brushes of the system colors. The best way to do this is to create a style for the listbox. Place the style in the resources of a parent element. The following XAML snippet shows how to apply the style to the listbox.

Last modified: 2008-10-24 01:37:10 Copyright (c) by Christian Moser, 2011. Comments on this article Show all comments. Action(T) Delegate (System) Encapsulates a method that has a single parameter and does not return a value. To browse the .NET Framework source code for this type, see the Reference Source. public delegate void Action<in T>( T obj ) Type Parameters in T The type of the parameter of the method that this delegate encapsulates.

Parameters obj Type: T The parameter of the method that this delegate encapsulates. You can use the Action<T> delegate to pass a method as a parameter without explicitly declaring a custom delegate. Using System; using System.Windows.Forms; delegate void DisplayMessage(string message); public class TestCustomDelegate { public static void Main() { DisplayMessage messageTarget; if (Environment.GetCommandLineArgs().Length > 1) messageTarget = ShowWindowsMessage; else messageTarget = Console.WriteLine; messageTarget("Hello, World! ") The following example simplifies this code by instantiating the Action<T> delegate instead of explicitly defining a new delegate and assigning a named method to it. .NET Framework. Delegates - Using Action<T> as an argument in C# (mimicking a function pointer)

C# - How do you use Func<> and Action<> when designing applications. Checkbox trigger enable/disable textbox. Extension Methods (C# Programming Guide) Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.

Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type. The most common extension methods are the LINQ standard query operators that add query functionality to the existing System.Collections.IEnumerable and System.Collections.Generic.IEnumerable<T> types. To use the standard query operators, first bring them into scope with a using System.Linq directive.

Then any type that implements IEnumerable<T> appears to have instance methods such as GroupBy, OrderBy, Average, and so on. The following example shows how to call the standard query operator OrderBy method on an array of integers. Singleton (wzorzec projektowy) Rozważmy aplikację prowadzącą dla celów diagnostycznych dziennik zdarzeń. Poszczególne komponenty dodają wpis do dziennika, przekazując mu jego treść, natomiast dziennik określa, gdzie faktycznie zostanie on zapisany. Każdy komponent może uzyskać w dowolnym momencie dostęp do dziennika, zatem musi on być dostępny globalnie.To dziennik decyduje o tym, gdzie wpis zostanie faktycznie zapisany. Komponent musi jedynie przekazać jego treść.

Oznacza to istnienie pojedynczej instancji dziennika.Z dziennika mogą również korzystać komponenty wielokrotnego użytku, zatem nie powinny one być zależne od mechanizmów udostępniania zasobów specyficznych dla danej aplikacji. Singleton Cały proces jest niewidoczny dla użytkownika. Zalety: Wady: Singleton musi być ostrożnie stosowany w systemach wielowątkowych. Przypisy. Volatile and MemoryBarrier()... - Brad Abrams. One thing I love about my job is that I learn something new all the time. Today I got a little bit smarter about volatile. One of the devs on the Indigo team was asking about the double check locking pattern. Today the Design Guidelines doc says: public sealed class Singleton { private Singleton() {} private static volatile Singleton value; private static object syncRoot = new Object(); public static Singleton Value { get { if (Singleton.value == null) { lock (syncRoot) { Singleton.value = new Singleton(); return Singleton.value; He wanted to know if “volatile” was really needed.

That part I knew… what we news to me is there is a better way to do volatile, and that is with an explicitly memory barrier before accessing the data member.. So, here is the “fixed” double check locking example.. private static Singleton value; Singleton newVal = new Singleton(); // Insure all writes used to construct new value have been flushed. System.Threading.Thread.MemoryBarrier(); Thoughts? Problem wzajemnego wykluczania. Na przykład: Przypuśćmy, że sekcja kodu modyfikuje jakieś dane w kilku krokach. W tym samym czasie uruchamiany jest inny wątek, który próbuje odczytać te same dane. Ze względu na to, że dane są w trakcie modyfikacji przez pierwszy wątek, ich stan jest niespójny. Wynik działania drugiego wątku może być nieoczekiwany. Jeśli drugi wątek spróbuje ponadto zmodyfikować dane, staną się one niespójne i przestaną być użyteczne dla któregokolwiek z wątków. Wymuszanie wzajemnego wykluczania[edytuj | edytuj kod] Istnieją dwa sposoby do wymuszania wzajemnego wykluczania Rozwiązania sprzętowe[edytuj | edytuj kod] Na systemach jedno-procesorowych najczęstszym sposobem wzajemnego wykluczania w jądrach systemów operacyjnych jest wyłączenie przerwań dla jak najmniejszej ilości instrukcji kodu, chroniąc przed uszkodzeniem struktury dzielonych danych sekcji krytycznej.

Podobną operacją atomową jest “compare-and-swap” używana do synchronizacji nieblokującej dla list lączonych i innych struktur danych. Testy jednostkowe. Testy jednostkowe w Visual Studio. Autor: Piotr Zieliński Opublikowano: 2011-06-21 Wprowadzenie W czasach skomplikowanych i wielowarstwowych systemów informatycznych prawidłowe testowanie oprogramowania jest ogromnym wyzwaniem. Testy manualne wykonywane przez użytkowników są dobrym sposobem na walidację aplikacji, jednak dla rozbudowanych programów są zbyt czasochłonne. Dlatego dobrym uzupełnieniem są testy zautomatyzowane – są to programy do automatycznego (jak sugeruje nazwa) testowania aplikacji. Kod źródłowy zamieszczonych w artykule przykładów. Dlaczego warto używać testów zautomatyzowanych? Przede wszystkim raz napisane testy mogą być wykorzystywane wielokrotnie. Ponadto testy zautomatyzowane można uruchamiać regularnie o określonych porach lub na pewnych etapach produkcji. Czym są testy jednostkowe? Testy jednostkowe (ang. unit test) porównują oczekiwany wynik funkcji z rzeczywistym rezultatem.

Tabela 1. Rysunek 1. Właściwości dobrze napisanych testów jednostkowych Co należy testować w pierwszej kolejności? Rysunek 2. 1. Test jednostkowy. Test jednostkowy (ang. unit test) – w programowaniu metoda testowania tworzonego oprogramowania poprzez wykonywanie testów weryfikujących poprawność działania pojedynczych elementów (jednostek) programu – np. metod lub obiektów w programowaniu obiektowym lub procedur w programowaniu proceduralnym. Testowany fragment programu poddawany jest testowi, który wykonuje go i porównuje wynik (np. zwrócone wartości, stan obiektu, wyrzucone wyjątki) z oczekiwanymi wynikami – tak pozytywnymi, jak i negatywnymi (niepowodzenie działania kodu w określonych sytuacjach również może podlegać testowaniu). Zaletą testów jednostkowych jest możliwość wykonywania na bieżąco w pełni zautomatyzowanych testów na modyfikowanych elementach programu, co umożliwia często wychwycenie błędu natychmiast po jego pojawieniu się i szybką jego lokalizację zanim dojdzie do wprowadzenia błędnego fragmentu do programu.

Testy jednostkowe są również formą specyfikacji. Podział testów jednostkowych[edytuj | edytuj kod] Using Windows XP Visual Styles and PrintWindow in Windows Applications. Paul Hellyar Microsoft Corporation October 25, 2001 Summary: This article develops an augmented AltTab application, TaskSwitcher, as a framework for demonstrating how the new visual styles of Windows XP, and PrintWindow, can be used in Windows applications. (13 printed pages) Contents IntroductionTaskSwitcher ApplicationIntercepting Keyboard InputEnumerating Top-level Application WindowsPresenting the Top-level Application WindowsUsing Comctl32.dll Version 6Conclusion Introduction Microsoft® Windows® XP introduces a new visual style that provides an easy-to-use and richer user interface—for instance, windows with rounded corners, the more tactile appearance of the taskbar, and the UI elements that hot track when the mouse hovers over them.

Figure 1. Windows XP also introduces the new printing API, PrintWindow. For an introductory article on visual styles and applying them to an application, see the technical article Using Windows XP Visual Styles in the MSDN Library. TaskSwitcher Application. Singleton (wzorzec projektowy)/kod - Wikiźródła, teksty i materiały źródłowe. Z Wikiźródeł, repozytorium wolnych materiałów źródłowych public final class Singleton { private final static Singleton ourInstance = new Singleton(); public static Singleton getInstance() { return ourInstance; } //żeby uniknąć automatycznego tworzenia domyślnego, publicznego, bezargumentowego konstruktora private Singleton() { }} public final class Singleton { // należy zwrócić uwagę na użycie słowa kluczowego volatile private static volatile Singleton instance = null; public static Singleton getInstance() { if (instance == null) { synchronized (Singleton.class) { if (instance == null) { instance = new Singleton(); } } } return instance; } // żeby uniknąć automatycznego tworzenia domyślnego, publicznego, bezargumentowego konstruktora private Singleton() { } } public enum Singleton { //synchronizacja oraz unikatowość zapewniona przez maszynę wirtualną Javy INSTANCE } class Singleton(object): def __new__(type): if not '_instancja' in type.

__dict__: type. Masowa wysyłka maili przy użyciu SmtpClient. “Masowa” i “SmtpClient” w jednym zdaniu? Nie, to nie jest żart. Każdy, kto choć raz musiał wysyłać serię maili z poziomu kodu C# pomyśli, że zwariowałem. Blokowanie wątku, cała gama wyjątków, które może rzucić metoda Send(), czy obsługa stanu aplikacji po takim błędzie. To ważniejsze atrakcje, jakie możemy napotkać korzystając z tej klasy. Jest na to jedna prosta metoda. Wróć. Dzięki tej właściwości możemy zmienić tryb wysyłki z bezpośredniego (standardowo wybrany), łączącego się z serwerem poczty i blokującego wątek, na zapis wiadomości email do pliku .eml. No świetnie. Konfiguracja IIS’a opisana jest tutaj. Ważna uwaga na koniec. Teraz identyfikacja będzie juz prosta. C# - Mixed mode assembly is built against version 'v1.1.4322'

Using The Package Manager Console. This topic describes how to find, install, remove, and update NuGet packages using PowerShell commands. You can also work with packages using the Manage NuGet Packages dialog box. For more information, see [Using the Manage NuGet Packages dialog](Using-the Add-Library-Package-Reference-Dialog-Box). Using PowerShell commands is required if you want to install a package without having a solution open. It's also required in some cases for packages that create commands that you can access only by using PowerShell. Finding a Package From the Tools menu, select Library Package Manager and then click Package Manager Console. The Package Manager Console window is displayed. The two drop-down lists set default values that let you omit parameters from the commands you enter in the window: In the Package source list, select the default source (NuGet package feed) that you want your commands to use.

When you enter commands, you can override these defaults. Installing a Package Removing a Package. HTML5 Geolocation. SendKeys Class (System.Windows.Forms) SendKeys.SendWait Method (System.Windows.Forms) Sends the given keys to the active application, and then waits for the messages to be processed. public static void SendWait( string keys ) Parameters keys Type: System.String The string of keystrokes to send. Use SendWait to send keystrokes or combinations of keystrokes to the active application and wait for the keystroke messages to be processed. .NET Framework Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0 .NET Framework Client Profile Supported in: 4, 3.5 SP1 Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

Move window to top? Kiedy używam var? Słowo var zostało wprowadzone w C# 3.0, prawdopodobnie ze względu na LINQ i anonimowe typy. Jedni programiści za wszelką cenę unikają tego słowa kluczowego a drudzy zapomnieli o typach i zawsze korzystają var bo w końcu to nowy feature… Nawet Resharper sugeruje aby zawsze używać var ponieważ skraca to składnie.

Istnieje też spora trzecia grupa do której m.in. ja należę i postaram się pokazać kilka przykładów. Moja zasada jest prosta – używam var tylko jeśli w momencie deklaracji można wywnioskować typ, bez żadnych zgadywanek: var numbers = new int[]{23,3563,463}; var employeeManager = new EmployeeManager();// o ile to nie interfejsvar text = "Hello World"; Nie lubię natomiast konstrukcji następującej: var numbers = GetNumbers(); var manager = GetManager(); Dlaczego? Dlaczego więc niektórzy tak lubią var? Explore posts in the same categories:C# Managed Extensibility Framework część I.