Tuesday, December 2, 2014

BooleanToVisibilityConverter - alternative way

Quite a departure from the regular use of the visibility converter

Reference- http://architects.dzone.com/articles/goodbye?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+zones%2Fdotnet+%28.NET+Zone%29

Old Method
Visibility={Binding IsVisible,Converter={StaticResource BooleanToVisibilityConverter}}

New Method

Usage
<TextBlock Text="I am visible!"
                       Style="{StaticResource PhoneTextExtraLargeStyle}"
                       attachedProperties:Alt.IsVisible="{Binding IsVisible}"
                       />
Attached Property - Class

public static partial class Alt
    {
        public static readonly DependencyProperty IsVisibleProperty = DependencyProperty.RegisterAttached(
            "IsVisible", typeof(bool?), typeof(Alt), new PropertyMetadata(default(bool?), IsVisibleChangedCallback));

        private static void IsVisibleChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var fe = d as FrameworkElement;
            if (fe == null)
                return;

            fe.Visibility = ((bool?)e.NewValue) == true
                ? Visibility.Visible
                : Visibility.Collapsed;
        }

        public static void SetIsVisible(DependencyObject element, bool? value)
        {
            element.SetValue(IsVisibleProperty, value);
        }

        public static bool? GetIsVisible(DependencyObject element)
        {
            return (bool?)element.GetValue(IsVisibleProperty);
        }
    }

Thursday, November 27, 2014

10 things you might have missed about MVVM Light

http://www.spikie.be/blog/post/2013/04/12/10-things-you-might-have-missed-about-MVVM-Light.aspx

Tuesday, October 28, 2014

Great example of async and await

http://blog.roboblob.com/2014/10/23/awaiting-for-that-button-click/

WPF - Change the currently selected item style or the item that the mouse is currently over in a listbox

http://wpf.2000things.com/2014/10/24/1187-using-an-itemcontainerstyle-to-change-items-in-an-itemscontrol/

Tuesday, October 14, 2014

Data Binding in a nested element of a usercontrol to an ENUM in WPF

In .cs file

public enum Alignment
    {
        Horizontal,
        Vertical
    }

public Alignment UserAlignment

        {
            get
            {
                return _alignment;
            }
            set
            {
                _alignment = value;
            }
        }

In XAML file

xmlns:local="clr-namespace:MyNameSpace"
x:Name="MyControl"
.
.
.
.
.
.
<DataTrigger Binding="{Binding ElementName=MyControl,Path=UserAlignment}" Value="{x:Static local:Alignment.Vertical}">
                                    <Setter TargetName="TargetElement" Property="TargetProperty" >
                                        <Setter.Value>
Somevalue                  
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>

Saturday, October 4, 2014

Enums as bitarray

http://blog.falafel.com/entity-framework-enum-flags/

Monday, September 29, 2014

Threading concepts explained in detail

http://www.codeproject.com/Articles/821074/Net-Threading-You-Need-To-Know