Thursday, December 18, 2014

Solving WPF Binding ConverterParameter problem

Write a multiconverter instead:
<TextBlock FontSize="16" FontFamily="GE Inspira Medium" VerticalAlignment="Center" Foreground="Black">
 <TextBlock.Text >
<MultiBinding Converter="{StaticResource flowRateUnitConverter}">
<Binding Path="FlowRate"/>
<Binding Path="Unit"/>
</MultiBinding>                                   
</TextBlock.Text>
</TextBlock>


MultiConverter class
public class FlowRateUnitConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values[0] == null || values[1] == nullreturn string.Empty;
            float? flowRate=values[0] as float?;
            string unit = values[1] as string;
            string convertedValue = values[0].ToString();
            switch(unit)
            {
                case "L/Hr":
                    convertedValue = (flowRate.Value * 60).ToString();
                    break;
                default:
                    break;
 
            }
            return convertedValue;
        }
 
        public object[] ConvertBack(
            object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }

Wednesday, December 17, 2014

Get/Set property value in an object instance using reflection

public static object GetPropValue(T src, string propName)
{
  return src.GetType().GetProperty(propName).GetValue(src, null);
}

public static object SetPropValue(T src, string propName, object value)
{
  return src.GetType().GetProperty(propName).SetValue(src, value);
}

Wednesday, December 10, 2014

WPF Performance Issues and knowledge about UI rendering

http://www.codeproject.com/Articles/784529/Solutions-for-WPF-Performance-Issue

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/

Monday, September 29, 2014

Threading concepts explained in detail

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

Thursday, September 25, 2014

Zoom on graph with XAML code

http://csharphelper.com/blog/2014/09/zoom-on-a-graph-with-xaml-code-c/

Tuesday, September 23, 2014

Bounce any control in WPF

http://wpf.2000things.com/2014/09/23/1164-using-animation-to-bounce-a-control/

Friday, September 19, 2014

Text recognition capability - Now read text from images

Microsoft OCR Library for Windows Runtime

http://blogs.windows.com/buildingapps/2014/09/18/microsoft-ocr-library-for-windows-runtime/

Thursday, August 28, 2014

Asynchronous Tasks Simplified

Superb article and nice explanation
http://visualstudiomagazine.com/articles/2014/08/01/manage-asynchronous-tasks.aspx

Wednesday, August 27, 2014

Rendering custom shape in WPF

http://wpf.2000things.com/2014/08/27/1145-using-rendersize-in-custom-shape/

Tuesday, August 26, 2014

WPF Creating SolidColorBrush From Hex Color Value

private static readonly SolidColorBrush connectedBrush = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFD5D5D5"));

Thursday, August 14, 2014

WPF - Passing string to ConverterParameter

<sys:String x:Key="mystring">The time of the day is </sys:String>

<TextBlock Text="{Binding Source={x:Static sys:DateTime.Now}, Converter={StaticResource custConverter},ConverterParameter={StaticResource mystring}}" />

Wednesday, August 13, 2014

How to 'merge' a XAML file and its code-behind with Visual Studio

You need to edit the .csproj file. Find the <Compile> element for MyTemplate.cs, and add a <DependentUpon> element under it:
<Compile Include="MyTemplate.cs">
  <DependentUpon>MyTemplate.xaml</DependentUpon>
</Compile>

Tuesday, August 12, 2014

Combine DataTrigger and Trigger in a WPF MultiDataTrigger

<MultiDataTrigger>
 <MultiDataTrigger.Conditions>
         <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True"/>
  <Condition Binding="{Binding Path=Model.IsRunning, Mode=OneWay}" Value="false"></Condition>
 </MultiDataTrigger.Conditions>
        <Setter TargetName="OuterBorder" Property="Background" Value="{StaticResource DarkBrushMouseOver}" />
</MultiDataTrigger>

Wednesday, July 23, 2014

Implement IEquatable in a Generic Type

http://csharp.2000things.com/2014/07/22/1143-implement-iequatable-in-a-generic-type/

How can I get the URL to the Web page the clipboard was copied from?

http://blogs.msdn.com/b/oldnewthing/archive/2014/07/21/10543803.aspx

Tuesday, July 22, 2014

Books & blogs

http://www.codeproject.com/Reference/676481/A-Gallery-of-Useful-Programming-Books

http://blog.pluralsight.com/social-media-tech-guide

Ultimate list of programing blogs
http://blog.developers.ba/ultimate-list-programming-blogs-follow-today

Windows Phone 8.1 Development Plan
https://onedrive.live.com/view.aspx?resid=635551367E71F947!74917&cid=635551367e71f947&app=WordPdf

http://visualstudiomagazine.com/Home.aspx

Windows 8 Apps Revealed Using XAML and C# by Adam Freeman

-APress

PluralSight:- http://blog.pluralsight.com/top-programming-languages

Some other cool blogs:

Wednesday, July 9, 2014

Tuesday, July 1, 2014

Install .Net Framework 3.5 on Windows 8 machine

How to install .NET Framework 3.5 on Windows 8 machine

  • Installation from Windows discs – you can get .NET Framework 3.5 from the genuine upgrade or installation discs for Windows 8 or from the genuine installation discs of Windows 7 and Vista SP1. 

Automatic installation

The computer should automatically detect the need for .NET Framework 3.5 and you’ll see a pop-up window like the one pictured below.
Simply select ‘Download and install this feature’ and Windows 8 will download the necessary files and install them for you.
User-added image

Manual installation

 Step 1 

From your desktop (you can navigate there by using the Windows key on your keyboard), open the right-hand sidebar menu (by moving your mouse pointer to the top or bottom right-hand corner of your screen) and select ‘Settings’.
User-added image

 Step 2 

From the Settings menu, select ‘Control Panel’.
User-added image

 Step 3 

From Control Panel, select ‘Uninstall a program’.
User-added image

 Step 4 

On the left-hand side of the next window, select ‘Turn Windows features on or off’.
User-added image

 Step  5 

Check the box to enable ‘.NET Framework 3.5 (includes .NET 2.0 and 3.0)’ and then click ‘OK’. This might take several minutes to process.
User-added image

Step 6

When the installation finishes, click ‘Close’ to complete.
User-added image

Not working?

Try restarting your computer, check that your internet is working and then try the installation steps again. If it’s still not working, you can also try installing it from the installation/upgrade discs.

Windows installation discs

 Step 1 

Insert your Windows installation/upgrade disc, wait a few moments and then hold the Windows key and press the letter ‘E’ to open ‘Computer’.

 Step  2 

Take note of the letter assigned to your Windows installation/upgrade disc drive as you’ll need this shortly. In this example, you can see the letter is ‘I’.
User-added image

Step 3

From the Windows Start menu (you can navigate there using the Windows key on your keyboard), type ‘cmd’ to search for the ‘Command Prompt’ application.
User-added image

Step 4

Right-click ‘Command Prompt’ and choose ‘Run as administrator’, from the bottom of your screen (if you’re presented with a ‘User Account Control’ pop-up window, click ‘Yes’ to continue).
User-added image

Step 5

Copy the bold line of text below by first; highlighting it with your mouse, and then holding the ‘Ctrl’ and ‘C’ keys.
dism /online /enable-feature /featurename:netfx3 /all /source:X:\sources\sxs /limitaccess

Step 6

Paste the text into the Command Prompt window by right-clicking your mouse in the window and selecting ‘Paste’ from the drop-down menu.
User-added image

Step 7

Replace the capital ‘X’ in the line of text with the letter for the source drive that you got from Step 2. You can navigate to it by using the arrow keys on your keyboard.

In this example, the correct source drive is ‘I’ – yours may be different.
User-added image

Step 8

Once you’ve input the correct source drive, press the ‘Enter’ key. If everything goes to plan, you’ll see this confirmation message.
User-added image

Tuesday, June 24, 2014

How to Concatenate Collections into Strings

http://visualstudiomagazine.com/blogs/tool-tracker/2014/06/join-collections-into-strings.aspx

Friday, June 6, 2014

Top 5 Visual Studio Features

http://blogs.msdn.com/b/visualstudiouk/archive/2014/05/30/my-top-5-visual-studio-features.aspx

Wednesday, May 7, 2014

Next-Generation Development with Application Insights

http://msdn.microsoft.com/en-us/magazine/dn683794.aspx

Wednesday, April 23, 2014

XAML ListView–Styling Items Based on Data (Windows 8.1 XAML), New use of converter

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2014/04/23/xaml-listview-styling-items-based-on-data-windows-8-1-xaml.aspx

Wednesday, January 8, 2014