Silverlight Navigator control and parameters

Silverlight Navigator control and parameters

Old forum URL: forums.lhotka.net/forums/t/5667.aspx


dnwheeler posted on Friday, October 24, 2008

Perhaps I'm missing something but it doesn't look like there's any way to automatically send parameters using the NavigationProvider control. Specifically, I have several controls (HyperlinkButtons) on a page that all navigate to the same page, but need to provide different parameters.

The OnBeforeNavigation event gives me an opportunity to set the parameters, but by that point, I've lost the context of the control that initiated the navigation.

Is the code simply not complete, or is the current design inadequate for this type of navigation (specifically, navigating to a new page with parameters)? If the latter, then I'll work on modifying the code to suit my needs (add a Parameters property to the NavigationProvider and add a Parameters parameter to the Navigate method on the Navigator).

--Doug

dnwheeler replied on Friday, October 24, 2008

I've gone ahead and made the changes I mentioned (added a Parameters property to the NavigationProvider and added a Navigate overload on the Navigator that takes a parameters string). That was very easy and works great (IMO, this should be added to the official CSLA code).

The next problem I've run into is that due to the asynchronous nature of Silverlight WCF calls, I don't know the title of the page until too late. Right now, the parameter passed to a page is a record number, and in the "SetParameters" call, I start a fetch of the record. The problem is that the ISupportNavigation.Title property is read before the data has been fetched, so I can't provide a meaningful (i.e. contextual) title.

Any thoughts on dealing with this issue? Is there some way to change the title later or postpone the step of adding the bookmark to the navigation history?

--Doug

sergeyb replied on Friday, October 24, 2008

Thanks, Doug.  I will try to work on incorporating your suggestions today and next week.  Could you elaborate a little on the need to have parameters property in Navigator control?  I am not 100% sure I understand why you needed this.

 

Thanks.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: dnwheeler [mailto:cslanet@lhotka.net]
Sent: Friday, October 24, 2008 2:49 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] Silverlight Navigator control and parameters

 

I've gone ahead and made the changes I mentioned (added a Parameters property to the NavigationProvider and added a Navigate overload on the Navigator that takes a parameters string). That was very easy and works great (IMO, this should be added to the official CSLA code).

The next problem I've run into is that due to the asynchronous nature of Silverlight WCF calls, I don't know the title of the page until too late. Right now, the parameter passed to a page is a record number, and in the "SetParameters" call, I start a fetch of the record. The problem is that the ISupportNavigation.Title property is read before the data has been fetched, so I can't provide a meaningful (i.e. contextual) title.

Any thoughts on dealing with this issue? Is there some way to change the title later or postpone the step of adding the bookmark to the navigation history?

--Doug



dnwheeler replied on Friday, October 24, 2008

Basically, I have a databound list of HyperlinkButtons representing data records. Clicking on any of the links navigates to a details page to display the record details. To do this, I have the NavigatorProvider's Parameters property (that I added) databound to the record ID. This way, the Navigator then then call the control factory to create the details page and then send the ID as the parameter.

The XAML for the Hyperlink Button looks like this:

<HyperlinkButton Height="16"
                 csla:NavigatorProvider.NavigatorProvider="{StaticResource NavProvider}"
                 csla:NavigatorProvider.ControlTypeName="TheApp.DetailsPage, TheApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                 csla:NavigatorProvider.Parameters="{Binding Id}"
                 csla:NavigatorProvider.TriggerEvent="Click">
    <HyperlinkButton.Content>
        ...
    </HyperlinkButton.Content>
</HyperlinkButton>

The HyperlinkButton.Content contains an icon and text that databinds to another property. Doing this allows navigation to the details page for any of the items without any associated code.

The details page then loads its contents (the complete record associated with the Id from the HyperlinkButton) when the SetParameters method is called.

BTW, the change I made to Navigator.cs is very simple:

public void Navigate(string controlTypeName)
{
    Navigate(controlTypeName, string.Empty);
}

public void Navigate(string controlTypeName, string parameters)
{
    NavigationEventArgs args = new NavigationEventArgs(controlTypeName, parameters, false);
    ...

And in the NavigatorProvider, I added a new dependency property called "Parameters" and pass its value to the new Navigate method.

--Doug

sergeyb replied on Friday, October 24, 2008

Got you.  Parameters property is for navigator provider, not navigator itself.  This makes sense.  I will post a reply to this thread once this change is done.  It seems like a very good suggestion.

 

Thanks again.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: dnwheeler [mailto:cslanet@lhotka.net]
Sent: Friday, October 24, 2008 4:58 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Silverlight Navigator control and parameters

 

Basically, I have a databound list of HyperlinkButtons representing data records. Clicking on any of the links navigates to a details page to display the record details. To do this, I have the NavigatorProvider's Parameters property (that I added) databound to the record ID. This way, the Navigator then then call the control factory to create the details page and then send the ID as the parameter.

The XAML for the Hyperlink Button looks like this:

<HyperlinkButton Height="16"
                 csla:NavigatorProvider.NavigatorProvider="{StaticResource NavProvider}"
                 csla:NavigatorProvider.ControlTypeName="TheApp.DetailsPage, TheApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                 csla:NavigatorProvider.Parameters="{Binding Id}"
                 csla:NavigatorProvider.TriggerEvent="Click">
    <HyperlinkButton.Content>
        ...
    </HyperlinkButton.Content>
</HyperlinkButton>

The HyperlinkButton.Content contains an icon and text that databinds to another property. Doing this allows navigation to the details page for any of the items without any associated code.

The details page then loads its contents (the complete record associated with the Id from the HyperlinkButton) when the SetParameters method is called.

BTW, the change I made to Navigator.cs is very simple:

public void Navigate(string controlTypeName)
{
    Navigate(controlTypeName, string.Empty);
}
 
public void Navigate(string controlTypeName, string parameters)
{
    NavigationEventArgs args = new NavigationEventArgs(controlTypeName, parameters, false);
    ...

And in the NavigatorProvider, I added a new dependency property called "Parameters" and pass its value to the new Navigate method.

--Doug



sergeyb replied on Friday, October 24, 2008

Thanks.  I just checked in a set of changes.   Here is description from bug tracker.

“Make improvements to Navigator.  Add more information to ISupportNavigation.  Add LoadCompleted event and CreateBookmarkAfterLoadCompleted.  Add ParametersProperty from NavigatorProvider”

 

So, this addresses your main suggestion as well as provides the way to deal with delayed bookmarking.  In control that need to load data, then set the title, return True for CreateBookmarkAfterLoadCompleted property, otherwise return False.  After the data is loaded, simply raise LoadCompleted event, signaling to data provider that the control is ready for title setting and bookmarking.  You can look at either CS or VB version of NavigationApp sample solution (in samples/Cslalight folder)  for a sample implementation that I used for testing of this change.

 

Thanks again for your suggestion.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: dnwheeler [mailto:cslanet@lhotka.net]
Sent: Friday, October 24, 2008 4:58 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Silverlight Navigator control and parameters

 

Basically, I have a databound list of HyperlinkButtons representing data records. Clicking on any of the links navigates to a details page to display the record details. To do this, I have the NavigatorProvider's Parameters property (that I added) databound to the record ID. This way, the Navigator then then call the control factory to create the details page and then send the ID as the parameter.

The XAML for the Hyperlink Button looks like this:

<HyperlinkButton Height="16"
                 csla:NavigatorProvider.NavigatorProvider="{StaticResource NavProvider}"
                 csla:NavigatorProvider.ControlTypeName="TheApp.DetailsPage, TheApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                 csla:NavigatorProvider.Parameters="{Binding Id}"
                 csla:NavigatorProvider.TriggerEvent="Click">
    <HyperlinkButton.Content>
        ...
    </HyperlinkButton.Content>
</HyperlinkButton>

The HyperlinkButton.Content contains an icon and text that databinds to another property. Doing this allows navigation to the details page for any of the items without any associated code.

The details page then loads its contents (the complete record associated with the Id from the HyperlinkButton) when the SetParameters method is called.

BTW, the change I made to Navigator.cs is very simple:

public void Navigate(string controlTypeName)
{
    Navigate(controlTypeName, string.Empty);
}
 
public void Navigate(string controlTypeName, string parameters)
{
    NavigationEventArgs args = new NavigationEventArgs(controlTypeName, parameters, false);
    ...

And in the NavigatorProvider, I added a new dependency property called "Parameters" and pass its value to the new Navigate method.

--Doug



dnwheeler replied on Monday, October 27, 2008

Sergey,

I've tried everything out and it works great! This solves all my issues with navigation (and allowed me to get rid of my own similar/inferior implementation).

Thanks for your time and effort.

--Doug

sergeyb replied on Monday, October 27, 2008

My pleasure.  I am glad it worked out for you.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: dnwheeler [mailto:cslanet@lhotka.net]
Sent: Monday, October 27, 2008 2:13 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: Silverlight Navigator control and parameters

 

Sergey,

I've tried everything out and it works great! This solves all my issues with navigation (and allowed me to get rid of my own similar/inferior implementation).

Thanks for your time and effort.

--Doug



Copyright (c) Marimer LLC