Tuesday, November 27, 2018

Truncated month/year in DatePicker

I spent about an hour reading the DatePicker template to figure this out.


As you can see, the month/year label is truncated. Even though it doesn't look like one, this control is a button. Searching through my styles (thank goodness I have them all in one place), I find this style...


<Style TargetType="{x:Type Button}">
    <Setter Property="Margin" Value="1"/>
    <Setter Property="HorizontalAlignment" Value="Right"/>
    <Setter Property="Width" Value="100"/>
    <Setter Property="Height" Value="22"/>
</Style>


This sets the height of all buttons to 22 px by default, including the buttons in the date pickers.


  • I could duplicate the DatePicker template and use a different style for this button. 
  • I could give this style a key and explicitly reference it for all other buttons. 
  • I could set the default height of all buttons to 25 px.



<Style TargetType="{x:Type Button}">
    <Setter Property="Margin" Value="1"/>
    <Setter Property="HorizontalAlignment" Value="Right"/>
    <Setter Property="Width" Value="100"/>
    <Setter Property="Height" Value="25"/>
</Style>



Wednesday, November 7, 2018

Problems breaking while debugging a MT call from worker thread

This is an obscure problem. It probably won't happen to you, but if it does - here's an explanation.

I am using WCF to call middle-tier code that can take a while to complete. To keep the users happy, I'm calling the middle tier from a worker thread, updating a database record periodically from the middle tier, and monitoring the database record and updating the UI from the UI thread. This all works very well.

But if I'm debugging in the middle tier and kill the process by clicking the Stop Debugging button, the thread completes instead of aborting and I can't debug on the MT any more (it doesn't hit any break points). I have to close and restart Visual Studio to be able to hit break points on the middle tier again.

This is similar to attaching to a process, for example when debugging a service. It occurs to me that Visual Studio may be using a similar process because I'm making the WCF call from a non-UI thread. When debugging a service you have to be sure to stop the debugger by clicking Terminate All from the Debug menu entry.

I tried clicking Terminate All while debugging my WCF service and everything worked correctly. The thread did not continue and I was able to hit break points on subsequent debug sessions.