Monday, October 19, 2015

Binding to a user control property

This is for Framework 4.0.

I have a page with a user control on it. The user control contains a list and I want to display the count of items in the list in a text block on the main page. It was obvious I would need to create a dependency property in the user control, so...

Public Shared ReadOnly CountProperty As Windows.DependencyProperty = Windows.DependencyProperty.Register("AttachmentCount", GetType(Integer), GetType(Attachments), Nothing)

Public Property AttachmentCount As Integer
Get
    Return CInt(GetValue(CountProperty))
End Get
Set(value As Integer)
    SetValue(CountProperty, value) 
End Set
End Property

Now it's a simple matter of binding the textblock to the user control's property, right?

<TextBlock Name="AddAttachmentsCount" Text="{Binding ElementName=AddAttachmentsUserControl, Path=AttachmentCount"/>

Oops, now I'm seeing an error in the output window at run-time...


System.Windows.Data Error: 40 : BindingExpression path error: '(AttachmentCount)' property not found on 'object' ''UserControl' (Name='AddAttachmentsUserControl')'. BindingExpression:Path=AttachmentCount; DataItem='UserControl' (Name='AddAttachmentsUserControl'); target element is 'TextBlock' (Name='AddAttachmentsCount'); target property is 'Text' (type 'String')

Well maybe I can bind the AttachmentCount property to the text property of my textblock as I define the instance of my user control...


<local:Attachments x:Key="AddAttachments" AttachmentCount="{Binding ElementName=AddAttachmentsCount, Path=Text, Mode=TwoWay}"/>

Yay!


Tuesday, October 13, 2015

Installing Reporting Services

The second time I've had to install Reporting Services I have decided to create a blog. If I were smarter I would have done it the first time.

We have a curious situation where we have Reporting Services partially installed. Perhaps it was installed for an earlier version of SQL Server but not upgraded so now when I run SQL Server xxxx Reporting Services Configuration Manager it cannot find an instance and the screen looks like this...


Follow these steps.

  1. Insert your SQL Server installation DVD and when SQL Server Installation Center pops up click on "Installation" on the left and then "New SQL Server stand-alone installation or add features to an existing installation" on the right.
  2. Click [Next >] in the wizard until you get to Installation Type.
  3. Select the "Add features to an existing instance" radio button and select the instance. Click [Next >]
  4. Check the "Reporting Services - Native" checkbox (unless you wanted sharepoint). Click [Next >] until you get to the [Install] option
  5. Click [Install]. Have a cup of tea and read the newspaper. Click [Close]
Configure your new Reporting Service

  1. Run Reporting Services Configuration Manager. The Report Server Instance should now be populated
  2. Click [Connect]
  3. Click Service Account on the left. The default service account is ReportServer. This is good.
  4. Click Web Service URL on the left. The default Virtual Directory is ReportServer. This is good. Click [Apply]
  5. Click Database on the left. There is no default database so click [Change Database]
     - You will probably want to create a new report server database. Click [Next]
     - Enter the server name and authentication used to create the new databases. I default to Current User - integrated security. Click [Next] and [Finish]
  6. Click Report Manager URL on the left. The default virtual directory is "Reports". This is good. Click [Apply]
  7. That's all you have to do. You can exit the application now.
Now go to my previous blog on enabling non-administrator access to a new instance of reporting services at http://wpfthoughts.blogspot.com/2015/05/running-report-manager-on-newly.html

Friday, October 9, 2015

Flicker and fail with Clickonce and Citrix

We deployed our first widespread WPF application recently and our Citrix users were experiencing a weird problem with the ClickOnce process. When they attempted to perform the install their mouse cursor started flickering and they got a black screen. The Citrix server was still running Server 2003 which is obsolete so tech support blamed the version of IE (8). I installed the Citrix receiver app on my computer and I was able to install the WPF application without a problem. What gives?

Some sleuthing revealed a hot fix http://support.microsoft.com/en-us/kb/955692 which describes our environment and the symptoms reported. It also mentions that the problem only affects non-administrators on the Citrix server (I am an administrator) which explains why I had no problems.

Maybe someone will find this useful.

Tuesday, October 6, 2015

ICO files in WPF applications

Well the last blog entry was a bit lengthy so here's a nice short one. Is has to do with assigning a ico file to a WPF project. The ico file contains a set of graphics at different resolutions in a single file and is used by WPF for the taskbar, the alt-tab, and window graphics like this...




Setting the ico file is simple. You add it to your project and reference it in the project properties under the application tab like this.

Setting the ico file for a WPF project
The problem is that when you are debugging in visual studio the ico file is not used because you are actually running against a proxy exe called vshost.exe. If this is a problem for you there are two solutions.


  1. Disable the visual studio hosting process in the debug tab of the project properties. This causes you to debug against the actual executable that has the ico file. I don't know why the proxy doesn't have it.
  2. Explicitly specify the ico file in the main page XAML like this.
    <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Icon="Images\pur.ico" .../>
  Take your pick.