IE9 - System.ArgumentException at browser history navigation in Silverlight 4 navigation application with custom attached DependencyProperty for Hyperlinkbutton
hello
i have strange problem ie9 in silverlight navigation app. the sl app consists of frame in display 4 pages. if call pages in loose order 1 @ time clicking on hyperlinkbutton in sl app , use browser history only move backwards, works fine in generell.
but iff then navigate forward in browser history, code ends running code in navigationfailed event , throws system.argumentexception. an evaluation of e.uri when debugging indicates value of uri empty.
also, system.argumentexception thrown if navigates through pages of pages in following order:
starting point: home page1 (frame.navigate(...) in constructor called mainpage.xaml.vb)
action: click on hyperlinkbutton p2-> navigate page2
action: click on button in browser-> navigation page1
action: click on forward button in browser-> navigate page2
action: click on button in browser-> navigationfalied() system.argumentexception (empty uri)
the historical data displayed in browser right clicking on forward or backward button correspond historical sequence of page views.
the journalownership property of frame has value auto.
i recently installed ie9 (x32). previously using ie8 (x 32). in ie8 (x 32) problem not occure, same code.
looking source of error, have checked how other navigation applications behave, have developed. the result there problem doesn't appear.
i therefore assume error source in special project in error thrown. that why i'll show essential source below.
a few notes on project's source code:
task of project test use of custom attached dependencyproperty (iskeepfocusvisualproperty), have created. this attached dependencyproperty has task manage 2 visualstates (isselected and isnotselected) of additional visualstategroup (keepfocusvisualstates) customized hyperlinkbutton template. these visualstates simulate the focus clicked hyperlinkbutton visually, even when hyperlinkbutton has no longer the focus. thus, hyperlinkbutton receive visual indicator displayed page.
the attached dependencyproperty iskeepfocusvisualproperty is defined in class hyperlinkbuttonextension.vb. it used in routine controlisselectedstate() in mainpage.xaml.vb. controlisselectedstate() hangs on navigated() event of frame. in event handling value of iskeepfocusvisualproperty set dynamically each of hyperlinkbutton. set to true hyperlinkbutton, clicked, , set false other hyperlinkbuttons. in propertychangedcallback of iskeepfocusvisualproperty (oniskeepfocusvisualpropertychanged) visualstate isselected or visualstate isnotselected activated then, depending on whether new value of iskeepfocusvisualproperty true or false.
as said, works in ie8 (x32). since installed ie9 yesterday morning, system.argumentexception thrown described effects of flow when using browser history navigation.
this main source code of project (the rest of source code for the 4 pages):
mainpage.xaml:
<usercontrol xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:silverlaw="clr-namespace:keephyperlinkbuttonfocusvisually.silverlaw" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" mc:ignorable="d" x:class="keephyperlinkbuttonfocusvisually.mainpage" width="560" height="600"> <grid x:name="layoutroot" background="#ff282828"> <grid.rowdefinitions> <rowdefinition height="80" /> <rowdefinition /> </grid.rowdefinitions> <stackpanel x:name="spcontainer" horizontalalignment="center" orientation="horizontal" verticalalignment="bottom"> <hyperlinkbutton x:name="hb1" content="home" verticalalignment="top" style="{staticresource keepfocusvisualhyperlinkbuttonstyle}" d:layoutoverrides="width" tag="home" margin="0,0,26,0" /> <hyperlinkbutton x:name="hb2" content="labs" tag="labs" margin="0,0,26,0" style="{staticresource keepfocusvisualhyperlinkbuttonstyle}" /> <hyperlinkbutton x:name="hb3" content="solutions" tag="solutions" margin="0,0,26,0" style="{staticresource keepfocusvisualhyperlinkbuttonstyle}" /> <hyperlinkbutton x:name="hb4" content="about" tag="about" margin="0,0,26,0" style="{staticresource keepfocusvisualhyperlinkbuttonstyle}" /> </stackpanel> <button x:name="b1" content="button" horizontalalignment="left" verticalalignment="top" width="75" /> <sdk:frame x:name="contentframe" grid.row="1" margin="20,20,20,40"/> </grid> </usercontrol>
silverlawhyperlinkbuttonstyle.xaml (ein resourcedictionary):
<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:keephyperlinkbuttonfocusvisually_silverlaw="clr-namespace:keephyperlinkbuttonfocusvisually.silverlaw" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:ignorable="d"> <!-- hier werden einträge für ressourcenverzeichnisse definiert. --> <style x:key="keepfocusvisualhyperlinkbuttonstyle" targettype="hyperlinkbutton"> <setter property="foreground" value="#ff73a9d8" /> <setter property="padding" value="2,0,2,0" /> <setter property="cursor" value="hand" /> <setter property="horizontalcontentalignment" value="left" /> <setter property="verticalcontentalignment" value="top" /> <setter property="background" value="transparent" /> <setter property="template"> <setter.value> <controltemplate targettype="hyperlinkbutton"> <grid background="{templatebinding background}" cursor="{templatebinding cursor}"> <visualstatemanager.visualstategroups> <visualstategroup x:name="commonstates"> <visualstate x:name="normal" /> <visualstate x:name="mouseover"> <storyboard> <doubleanimation duration="0" to="1" storyboard.targetproperty="(uielement.opacity)" storyboard.targetname="mouseovervisual" d:isoptimized="true" /> </storyboard> </visualstate> <visualstate x:name="pressed" /> <visualstate x:name="disabled"> <storyboard> <objectanimationusingkeyframes duration="0" storyboard.targetproperty="visibility" storyboard.targetname="disabledoverlay"> <discreteobjectkeyframe keytime="0"> <discreteobjectkeyframe.value> <visibility>visible</visibility> </discreteobjectkeyframe.value> </discreteobjectkeyframe> </objectanimationusingkeyframes> </storyboard> </visualstate> </visualstategroup> <visualstategroup x:name="focusstates"> <visualstate x:name="focused"> <storyboard> <doubleanimation duration="0" to="1" storyboard.targetproperty="(uielement.opacity)" storyboard.targetname="focusvisual" d:isoptimized="true" /> </storyboard> </visualstate> <visualstate x:name="unfocused" /> </visualstategroup> <!--additional visualstategroup holds 2 visualstates indicate iskeepfocusvisualproperty visually --> <visualstategroup x:name="keepfocusvisualstates"> <visualstate x:name="isnotselected" /> <visualstate x:name="isselected"> <storyboard> <doubleanimation duration="0" to="1" storyboard.targetproperty="(uielement.opacity)" storyboard.targetname="keepfocusvisual" d:isoptimized="true" /> </storyboard> </visualstate> </visualstategroup> </visualstatemanager.visualstategroups> <textblock x:name="disabledoverlay" foreground="#ffaaaaaa" horizontalalignment="{templatebinding horizontalcontentalignment}" margin="{templatebinding padding}" text="{templatebinding content}" visibility="collapsed" verticalalignment="{templatebinding verticalcontentalignment}" canvas.zindex="1" /> <contentpresenter x:name="contentpresenter" contenttemplate="{templatebinding contenttemplate}" content="{templatebinding content}" horizontalalignment="{templatebinding horizontalcontentalignment}" margin="{templatebinding padding}" verticalalignment="{templatebinding verticalcontentalignment}" /> <!--this element responsible visual focus.--> <textblock x:name="focusvisual" horizontalalignment="{templatebinding horizontalcontentalignment}" textwrapping="wrap" text="{templatebinding content}" verticalalignment="{templatebinding verticalcontentalignment}" margin="{templatebinding padding}" foreground="#ffd8d073" opacity="0" /> <!--this element responsible visual effect on mouse over.--> <textblock x:name="mouseovervisual" margin="{templatebinding padding}" textwrapping="wrap" text="{templatebinding content}" d:layoutoverrides="width, height" horizontalalignment="{templatebinding horizontalcontentalignment}" verticalalignment="{templatebinding verticalcontentalignment}" canvas.zindex="1" foreground="#99f3f3f2" opacity="0" /> <!--this element responsible keeping focus visually. element mandatory--> <textblock x:name="keepfocusvisual" margin="{templatebinding padding}" textwrapping="wrap" text="{templatebinding content}" d:layoutoverrides="width, height" horizontalalignment="{templatebinding horizontalcontentalignment}" verticalalignment="{templatebinding verticalcontentalignment}" opacity="0" foreground="#ffd8d073" /> </grid> </controltemplate> </setter.value> </setter> </style> </resourcedictionary>
hyperlinkbuttonextension.vb:
namespace silverlaw public class hyperlinkbuttonextension public shared function getiskeepfocusvisual(byval hb as hyperlinkbutton) as boolean if hb is nothing then throw new argumentnullexception("hyperlinkbutton") end if return cstr(hb.getvalue(iskeepfocusvisualproperty)) end function public shared sub setiskeepfocusvisual(byval hb as hyperlinkbutton, byval value as boolean) if hb is nothing then throw new argumentnullexception("hyperlinkbutton") end if hb.setvalue(iskeepfocusvisualproperty, value) end sub public shared readonly iskeepfocusvisualproperty as dependencyproperty = dependencyproperty.registerattached("iskeepfocusvisual", gettype(boolean), gettype(hyperlinkbutton), new propertymetadata(new propertychangedcallback(addressof oniskeepfocusvisualpropertychanged))) shared sub oniskeepfocusvisualpropertychanged(byval d as dependencyobject, byval e as dependencypropertychangedeventargs) dim hb as hyperlinkbutton = ctype(d, hyperlinkbutton) if hb is nothing then throw new notsupportedexception("iskeepfocusvisual property valid hyperlinkbutton instance.") end if dim newvalue as boolean = cbool(e.newvalue) ' active / deactivate isselected / isnotselected visual state: if newvalue then visualstatemanager.gotostate(hb, "isselected", true) else visualstatemanager.gotostate(hb, "isnotselected", true) end if end sub end class end namespace
mainpage.xaml.vb:
partial public class mainpage inherits usercontrol public sub new() initializecomponent() ' travers children of stackpanel; ' please note: children inside stackpanel are ' of type hyperlinkbutton. keep in mind when add ' elements other of type hyperlinkbutton. in case ' have implement additional code checks ' type of each element before add delegate. for each element as hyperlinkbutton in spcontainer.children addhandler element.click, addressof navigatetosite next ' logic of keeping focus visually takes place in navigated() event. ' benefit of navigated() event is, focus can kept when ' user navigates app using browser history. addhandler contentframe.navigated, addressof controlisselectedstate ' here go initial site when app starts fisrt time. navigatetosite(hb1, nothing) end sub private sub navigatetosite(byval sender as object, byval e as routedeventargs) ' sender hyperlinkbutton user has clicked. ' in xaml of each hyperlinkbutton set name of ' page specific hyperlinkbutton shall navigate to ' value tag property. provides get ' page name , use value create uri. contentframe.navigate(new uri("/" + ctype(sender, hyperlinkbutton).tag.tostring + ".xaml", urikind.relativeorabsolute)) end sub private sub controlisselectedstate(byval sender as object, byval e as navigation.navigationeventargs) ' set focus on plug-in system.windows.browser.htmlpage.plugin.focus() ' name part of targeted page dim target as string = e.uri.originalstring.substring(1, e.uri.originalstring.indexof(cchar(".")) - 1) ' travers stackpanel container, containing hyperlinkbuttons for each elem in spcontainer.children ' check if tag value of hyperlinbutton fits name of targeted page if ctype(elem, hyperlinkbutton).tag.tostring = target then ' if fits, set iskeepfocusvisualproperty true ... elem.setvalue(silverlaw.hyperlinkbuttonextension.iskeepfocusvisualproperty, true) ' set focus on hyperlinkbutton ctype(elem, hyperlinkbutton).focus() else ' if doesn't fit, set iskeepfocusvisualproperty false elem.setvalue(silverlaw.hyperlinkbuttonextension.iskeepfocusvisualproperty, false) end if next end sub private sub contentframe_navigationfailed(byval sender as object, byval e as system.windows.navigation.navigationfailedeventargs) handles contentframe.navigationfailed dim debugstop as integer = 0 'contentframe.navigate(contentframe.currentsource) e.handled = true end sub end class
i have same problem hyperlinkbutton custom control has same functionality example above (holding additional visualstategroup in template 2 visualstates display isselectedproperty dependencyproperty of custom control visually). there running in ie8 , have same problem in ie9. if necessary, can possibly code custom control in addition post.any or idea on issue appreciated.
Expression > Expression Blend + SketchFlow
Comments
Post a Comment