11.11.2015

Singelton in C#

#region Singleton
       private static xxx _instance;

       private xxx() { }

       public static xxx Instance
       {
           get
           {
               if (_instance == null)
               {
                   _instance = new xxx();
               }
               return _instance;
           }
       }
       #endregion

c#-Code zu lesbarem HTML

http://csharpindepth.com/CodeFormatterTool.aspx

Converter, die man (fast) immer braucht

Sichtbarkeit über Bool (unsichtbar):

public class Boolean2VisibleConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is bool)
        {
            if ((bool)value)
                return Visibility.Visible;
        }
        return Visibility.Hidden;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Sichtbarkeit über Bool (ausgeblendet):

public class Boolean2VisibleCollapsedConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool)
            {
                if ((bool)value)
                    return Visibility.Visible;
            }
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }