string.join(",", Contacts.Select(x=>x.Name); //Name is a property of an object(Contact) in the list of Contacts
This blog is primarily a compilation of frequently faced issues by developers with solutions which I have implemented to solve them
Friday, November 6, 2015
Generate a comma separated string from an IEnumerable object
Labels:
C#,
comma separated string
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Wednesday, November 4, 2015
Simple yet effective way to find if IEnumerable has elements or not
bool IsEmpty(IEnumerable en)
{
foreach(var c in en) { return false; }
return true;
}
Labels:
C#,
IEnumerable
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Monday, October 19, 2015
C# code to get numbers after decimal point
int decimalPoints=BitConverter.GetBytes(Decimal.GetBits(value)[3])[2];
Labels:
C#,
Decimal Precision
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Saturday, October 10, 2015
How do you force authors or template stylists to force add a control
How do you force
authors or template stylists to force add a control
Solution- Provides
template authors the information that these parts are required for styling this
control -more like a contract
[TemplatePart [Name=TextBlockPart, Type =typeof(TextBlock))) public class MyControl : Control
{ private const string TextBlockPart as PART_TextBlock; TextBlock textblock; protected TextBlock Textßlock get { return textblock;} set { if (textßlock is null) ( textblock.Textlnput-= new TextCompositionEventHendler(textblockTextlnput) J
Labels:
Custom Control,
Template Part,
WPF
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Access TemplatedElements in CustomControl
How to access
TemplatedElements in CustomControl?
Override OnApplyTemplate in the .cs file. Its called everytime
a template is applied to a control
public override void OnApplyTenplate()
public override void OnApplyTenplate()
{ base.OnApplyTemplate(); var textblock= GetTemplateChild("Name Of Part") as TextBlock; textblock.Text="hello";
}
Labels:
Custom Control,
TemplatedElements,
WPF
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
How to get two way binding with Template Binding in WPF
Template Binding by default doesnt support Two Way binding.
If you still need to have it, here's the workaround:
<TextBox Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}"/>
If you still need to have it, here's the workaround:
<TextBox Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}"/>
Labels:
TemplatedParent,
TwoWay Binding,
WPF
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Tuesday, August 18, 2015
Free programming books
Labels:
free books
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Tuesday, August 4, 2015
Everything you wanted to know about Dynamo object - Building C# objects dynamically
Labels:
C# 6.0,
Dynamo object
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
WPF ItemsControl
Labels:
WPF Itemcontrol
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
No shake on hover
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
VS2015 Extensions
Labels:
VS2015 extensions
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Thursday, July 23, 2015
Service Oriented Solutions using MSMQ and WCF
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Friday, May 15, 2015
WPF MultiBindng Converter example
Without Converter
<TextBlock.Text> <MultiBinding StringFormat="{}[{0} - {1}]"> <Binding Path="Min" FallbackValue=""/> <Binding Path="Max" FallbackValue=""/> </MultiBinding> </TextBlock.Text> </TextBlock>
Using Converter
public class RangeMultiValueConvertor : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values == null) return string.Empty; if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue) { return string.Empty; } return (string.Format("[{0} - {1}]", values[0], values[1])); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { return null; } }<local:RangeMultiValueConvertor x:Key="rangeConverter"/>
<TextBlock.Text> <MultiBinding Converter="{StaticResource rangeConverter}"> <Binding Path="Min"/> <Binding Path="Max"/> </MultiBinding> </TextBlock.Text>
Labels:
MultiBindng Converter example,
WPF
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Thursday, April 2, 2015
JSonConverter - Serialize and Desrialize .Net
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Wednesday, April 1, 2015
Solution for textBox text change not updating the view model/model
<TextBox Name="textBox1"
Height="23" Width="463"
HorizontalAlignment="Left"
Margin="12,12,0,0"
VerticalAlignment="Top"
Text="{Binding OriginalText, UpdateSourceTrigger=PropertyChanged}" />
TheTextBox.Text
property has a default UpdateSourceTrigger value of LostFocus. This means if an application has a TextBox with a data-bound TextBox.Text property, the text you type into the TextBox does not update the source until the TextBox loses focus (for instance, when you click away from the TextBox).If you want the source to get updated as you are typing, set the UpdateSourceTrigger of the binding to PropertyChanged. In the following example, the Text properties of both the TextBox and the TextBlock are bound to the same source property. The UpdateSourceTrigger property of the TextBox binding is set to PropertyChanged.
Labels:
Binding,
Model,
TextBox TextChangedEvent,
ViewModel,
WPF
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Serialization Exception: PropertyChangedEventManager is not serializable
Since events are non serializable, here is the way out to deal the problem when serializing model classes which have a property changed event to notify the view model classes:
http://www.primordialcode.com/blog/post/serialization-exception-propertychangedeventmanager-serializable
[NonSerialized] private PropertyChangedEventHandler _PropertyChanged; public virtual event PropertyChangedEventHandler PropertyChanged { add { _PropertyChanged += value; } remove { _PropertyChanged -= value; } }
Labels:
Model classes,
MVVM,
Serialization,
ViewModel classes,
WPF
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Thursday, March 19, 2015
Remote Desktop Connection Shortcut
1. Right click on a empty area on desktop, and click on New and Shortcut.
2. Type the location below into the location area, and click on the Next button. (see screenshot below)
NOTE: Substitute ComputerName or IP.Address in the command below with the actual computer name or IP address of the computer that you want to make a RDC to.
2. Type the location below into the location area, and click on the Next button. (see screenshot below)
NOTE: Substitute ComputerName or IP.Address in the command below with the actual computer name or IP address of the computer that you want to make a RDC to.
mstsc.exe /v:ComputerName
OR
mstsc.exe /v:IP.Address
Labels:
Remote Desktop Connection
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Thursday, February 19, 2015
Inversion Of Control: Best Practices
Labels:
IoC,
OOPs,
Unity container
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Friday, February 6, 2015
12 Best Tutorials To Learn AngularJS
Labels:
Angular JS
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Thursday, February 5, 2015
A Simple ViewModelLocator for Spawning ViewModels for XAML Based Applications
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Saturday, January 10, 2015
Introduction to REST and .net Web API
Nice article by Martin Kearn on .Net Restful API's:
Labels:
.net Web API,
REST
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Friday, January 2, 2015
C# 6.0 New Features
http://www.kunal-chowdhury.com/2014/12/csharp-6-expression-bodied-method.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+kunal2383+%28Kunal%27s+Blog%29
Labels:
C# 6.0
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Nice article on IDataErrorInfo and Validation in WPF
http://www.codeproject.com/Articles/858492/WPF-Validation-Using-IDataErrorInfo
Labels:
IDataErrorInfo,
validation,
WPF
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Subscribe to:
Posts (Atom)