Posts Tagged: DoUNo


8
Jan 12

DoUNo: ApplicationBar in WindowsPhone is not bindable

ApplicationBar is not a FrameworkElment and is not bindable. Which implies that if you are so much used to MVVM and wants to bind things to ApplicationBar, its not easy; you need to create your own ApplicationBar.

This sounds pretty lame and I really don’t know why Microsoft is not interested in creating an ApplicationBar that is bindable.


29
Dec 11

DoUNo: You can tombstone an app using Windows Phone Emulator

Property page of a WP project

Property page of a WP project

You cannot predict when an app would be tombstoned in Windows Phone. But still you can simulate it by enabling a settings in the Property page of the Windows Phone project.

  1. Browse to the Property page of the Windows Phone project.
  2. Select the Debug tab.
  3. Select the Tombstone upon deactivation while debugging.
  4. Build and Run the project.
  5. After the app launches, click on the Windows key to deactivate the app, there by tombstoning it.

20
Jul 10

DoUNo: Whadds up with the Background property of a control

This is weird !! Try to customize the control template of a button,

  1. Place a grid as the base panel (don’t add any Background property to it)
  2. Add an ellipse and a content presenter to this
  3. Add a Click event handler to the button
  4. Run it and try to click on the white space, the event will not be raised !!!

Go back to the template,

  1. Add a Background property to the grid and set the value to Blue (can be any color other than transparent)
  2. Run it and try to click on the Blue color, the event will be raised !!!

Go back to the template,

  1. Set the value of the Background Property to Transparent
  2. Run it and try to click on the white space, the event will still be raised !!! (WHY ?!?)

Looks weird to me thou’


1
Feb 10

DoUNo: XAML gets compiled in to a BAML

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.


13
Jan 10

DoUNo: MDI in WPF

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.


3
Dec 09

DoUNo: Popup animation in wpf

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 :P ) and found that the popup animation shall work only if the AllowsTransparency of the popup is set to true. Really weird !!


6
Nov 09

DoUNo: Setting expectations on nullable type, NMock2

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 :P )


7
Jul 09

DoUNo: When to use StringFormatFlags.DirectionRightToLeft and StringAlignment.Far

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


17
Mar 09

DoUNo: SelectedItem or SelectedIndex properties will not be filled unless the control is painted in screen

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.


13
Mar 09

DoUNo: DisplayMember getting reset on DataSource=null

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