Wednesday, December 3, 2014

Refer WPF dictionary in another library

<UserControl x:Class="ProcessPictureUserControls.DualSensors"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:lib="clr-namespace:PPLibrary;assembly=PPLibrary1.12.0.1" 
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d" 
             Name="UserControl"
             d:DesignHeight="40" d:DesignWidth="200">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/PPLibrary1.12.0.1;component/Themes/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

.
.
.
<Border Name="InnerBorder" CornerRadius="20" Margin="3" BorderBrush="LightGray" Background="{StaticResource ResourceKey=DarkBrush}"  BorderThickness="{Binding Path=RegulationState, Mode=OneWay, Converter={StaticResource ResourceKey=regulationStateToBorderOnOffConverter},FallbackValue=1}" />

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/