Skip to content

Instantly share code, notes, and snippets.

/*
Sample of use:
<ComboBox ItemsSource="{Binding Source={ Extensions:ByteEnumerationExtention {x:Type type:MyEnum} }}" DisplayMemberPath="Description"
SelectedValuePath="Value" SelectedValue="{Binding SelectedItemInViewModel}"/>
public enum MyEnum : short
{
[Description("گزینه 1")]
Item1 = 1,
@Jalalx
Jalalx / TcpCommunication.cs
Created June 9, 2015 11:14
Represents Client and Server classes to communicate in TCP/IP networks.
using System;
using System.Net;
using System.Threading;
namespace System.Net.Sockets
{
public class Client
{
// Fields...
private Socket clientSocket = null;
@Jalalx
Jalalx / InterceptableViewModelBase.cs
Last active August 29, 2015 14:21
Implements INotifyPropertyChanged and MarshalByRefObject for interception in view models.
/// <summary>
/// Implements <see cref="INotifyPropertyChanged"/> and <see cref="MarshalByRefObject"/> for interception in view models.
/// </summary>
public abstract class InterceptableViewModelBase : MarshalByRefObject, INotifyPropertyChanged
{
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
@Jalalx
Jalalx / ILoggerFacadeExtensions.cs
Created April 29, 2015 21:20
Extensions for Prism ILoggerFacade interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Prism.Logging;
namespace Microsoft.Practices.Prism.Logging
{
public static class ILoggerFacadeExtensions
@Jalalx
Jalalx / IUnityContainerExtensions.cs
Created April 29, 2015 21:18
Unity extensions for WPF Prism apps
using System;
namespace Microsoft.Practices.Unity
{
public static class IUnityContainerExtensions
{
/// <summary>
/// Registers a ContentControl for navigation using the name parameter.
/// </summary>
/// <typeparam name="T">The type of ContentControl to register</typeparam>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Linq
{
public static class LinqExtensions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System
{
public static class StringExtensions
{
/*
How use in View?
<PasswordBox>
<i:Interaction.Behaviors>
<local:PasswordBoxBindingBehavior Password="{Binding Password}"/>
</i:Interaction.Behaviors>
</PasswordBox>
How access to orginal string?
@Jalalx
Jalalx / ILoadAware.cs
Created April 22, 2015 12:44
LoadAwareRegionBehavior raise ViewLoaded/ViewUnloaded methods when View.Loaded/View.Unloaded events raise.
using System;
namespace Microsoft.Practices.Prism.Regions
{
/// <summary>
/// Represent ILoadAware functionality for View-Model classes.
/// </summary>
public interface ILoadAware
{
/// <summary>
public abstract class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));