Archive for the ‘DoUNo’ tag
What does a xaml file gets compiled in to ? It gets compiled in to a baml (binary xaml). More @ wikipedia.
You can find the .baml file in the \obj\Debug folder.
WPF, out of the box doesn’t have provision for MDI windows. The reason is quite simple, MDI windows are outdated and most of the applications have been using tabbed documents, proving they are really easy to use. Although the framework is flexible enough for you to make such a feature, its better to move to tab based interface.
Every time I try adding a default animation (Slide, Fade, …) to a pop up in WPF, I find it not to be working. Today, I went thru’ MSDN (breaking my laziness
) and found that the popup animation shall work only if the AllowsTransparency of the popup is set to true. Really weird !!
Ever had a problem of setting an expectation for nullable objects?
If you wanna return false when .HasValue of a nullable object is called, then you cannot do it with the normal expect statement. Rather, try not returning any values, because NMock2 returns default value of HasValue (False) if nothing is set as return values in expect statements.
Here is a sample,
public interface IProduct //Interface that has a nullable member
{
int? ProductNo //Member that I wanna test and I wish to test the scenario in which this will be null
{
get;
}
}
IProduct aProduct= myMockery.NewMock<IProduct>();
//Stub.On(aProduct).GetProperty("ProductNo").Will(Return.Value(default(int?)); //this statement produces a runtime exception, so we have to use the following instead
Stub.On(aProduct).GetProperty("ProductNo"); //no return value is set, nmock2 returns false when .HasValue is queries
Hope this helped you.
Sudarsan Srinivasan
- on behalf of my friends (they found this hack
)
Recently I had a trouble displaying some values in a custom painted ListViewControl. I had to display some numbers right aligned. But I mistook this alignment with direction of the string, leading me to write the code as,
theArgs.Graphics.DrawString("100",
FONT_ISOVALUE_VALUE, Brushes.Black,
new Point(theArgs.Bounds.X + LOCATION_X_OFFSET, theArgs.Bounds.Y + LOCATION_Y_OFFSET),
new StringFormat(StringFormatFlags.DirectionRightToLeft));
This was working properly for positive values, but for negative values, the - sign comes after the number. i.e., instead of -100, it was displayed as 100-, thats when I understood the difference between RightToLeft text and right aligned texts. So replacing the above snippet with the following snippet does the work.
StringFormat aStringFormat = new StringFormat();
aStringFormat.Alignment = StringAlignment.Far;
theArgs.Graphics.DrawString("-100",
FONT_ISOVALUE_VALUE, Brushes.Black,
new Point(theArgs.Bounds.X + LOCATION_X_OFFSET, theArgs.Bounds.Y + LOCATION_Y_OFFSET),
aStringFormat );
So alignment is different and direction of text is different. Use StringFormat.Alignment for alignment and StringFormatFlags for direction
Recently, I was trying to write UnitTest for a panel. The panel had a ComboBox and the target method (method that needs to be tested) was populating the ComboBox with some DataSource, which is a collection of string. In my unit test driver (written in NUnit with NMock), I tried to check the item’s collection. It was always returning me null despite me adding some items to it. Even the SelectedItem and SelectedIndex were all returning me null. When I had a look in to the WinForms dll using reflector, I came to know about itemscollection .
It seems that this member will not be populated unless the ComboBox is painted in a layout.
So next time, when you are writing a unit test for controls, make sure that you create testcases that are testable (unlike me). Thanks to my colleague who pointed out a SO link that clearly talks about this.
I have a ComboBox whose items are set using the DataSource property. The DataSource is a collection of a custom object (that has a string property ‘Value’ and int property ‘Id’). In the initialise controls, I set the DisplayMember as Value and ValueMember as Id. Now I tried to clear the DataSource by calling,
myComboBox.DataSource = null;
When I did that, my ComboBox’s DisplayMember is reset to “” automatically. This was not I expected, but this is how it behaves as a .Net control. Thought it would be helful sharing it.
More @ http://stackoverflow.com/questions/641809/displaymember-getting-reset-on-datasourcenull
Today, I was trying to customise ListViewControl by playing with the item drawn event, thats when I came across this peculiar stuff.
In ListView, if you have subscribed for the ItemSelectionChangedEvent,the event will not be raised, if you select the same item more than once provided the ListView.MultiSelect = false; Shhh. Quite difficult to understand, isn’t it ??
Ok. An example, Lets consider that we have a list view control with two items, foo and bar. Also consider that we have subscribed for the ItemSelectionChangedEvent and the ListView’s MultiSelect is true. Now if you run the application keeping a break point in the ItemSelectionChangedEventHandler and if you select the item foo again and again the control will break. On the other hand, if your ListView’s MultiSelect is false, the control won’t hit the break point. Which means that the event will not be raised.
Its really simple to read a console’s text (contents) in C#. This can be done using the Console.In.ReadLine() method. The Console and the Console.In classes exposes a loads of methods that are really handy. Here is a small snippet that tries to print the directories in blue color and the others in default color in console when you type dir.
string aConsoleReadLine = null;
ConsoleColor aDefaultConsoleColor = Console.ForegroundColor;
while ((aConsoleReadLine = Console.In.ReadLine()) != null) //Reading the text from the console and storing it in a local variable
{
if (aConsoleReadLine.Contains("<DIR>")) //Check if it is a directory
{
Console.ForegroundColor = ConsoleColor.Blue;
}
else
{
Console.ForegroundColor = aDefaultConsoleColor;
}
Console.WriteLine(string.Format("{0}", aConsoleReadLine));
}
To run the above mentioned snippet, create a console app and put this snippet in your main method. Then, open up command prompt. In the command prompt type dir | <your_built_exe>.exe. We use | so that we can get the output to our program.
Yeah. One can overload operators in a structure (C#). Syntaxes are similar to that of class operator overloading, except for that fact that we need to operate on struct variables and not on class objects (obvious isn’t it ??).
For newbies — struct is of value type (stored in stacks) and classes are of reference types (stored in heaps)