3

Closed

Binding with a # in the text doesn't work

description

When navigating between one View and another, and setting a binding on an element which contains a # in the name, results in the bound value being String.Empty, rather than the original text.

Steps to reproduce:
  1. Open the attached Visual Studio Project
  2. Run the project in the Emulator
  3. When MainPage.xaml opens, notice that there is Test1, #Test2, Test3 and Test4 which are a BindableCollection<Project> which is Bound to a ListBox on the View
  4. Select Test1, which will cause a navigation to another view, using:
public void GoToBuildTypesPage(string projectId, string projectName)
    {
        navigationService.UriFor<BuildTypesViewModel>()
            .WithParam(x => x.ProjectId, projectId)
            .WithParam(x => x.ProjectName, projectName)
            .Navigate();
    }
  1. In the BuildTypesView, note that the text Test1 is now bound to the TextBlock on this view.
  2. Click the hardware back button
  3. Click #Test2 and notice that within the BuildTypesView, there is nothing in the TextBlock
  4. Click the hardware back button
  5. Click Test3 and in the BuildTypesView witness that the TextBlock is correctly bound.
Any ideas on what is going on here?

file attachments

Closed Dec 11, 2012 at 7:33 PM by EisenbergEffect
Fixed.

comments

deanvmc wrote May 12, 2012 at 1:38 PM

This is the WithParam method in the UriBuilder

public UriBuilder<TViewModel> WithParam<TValue>
(Expression<Func<TViewModel, TValue>> property, TValue value)
{
        if (!Equals(default(TValue), value)) 
        {
            queryString[property.GetMemberInfo().Name] = value.ToString();
        }

        return this;
}

As far as I can see, whatever parses out or rehydrates the query string doesn't like your hashed value and is eating it on you. Unfortunately I have to go out and didn't get that far. If you download the code its pretty much all in the UriBuilder.cs file.

deanvmc wrote May 12, 2012 at 4:22 PM

Hi guys just to add more info. I don't think this is a Caliburn.Micro bug. See the following details from my immediate window:

?e.Uri.ToString()
"/Views/BuildTypesView.xaml?ProjectId=2&ProjectName=#Test2"

?page.NavigationContext.QueryString["ProjectName"]
""

e.Content is converted from a NavigationEventArgs to a PhoneApplicationPage. It is at this point that the query string is converted from the above into a dictionary. This dictionary does NOT have the value with the hash in it.

deanvmc wrote May 12, 2012 at 4:55 PM

tibel wrote Dec 9, 2012 at 10:16 AM

Fixed with commit 668a8a04ad47