.net - System.InvalidOperationException: Specified element is already the logical child of another element. Disconnect it first message on windows 7 machine -
i have wpf application running without issues in windows 8 os development machine. when seek run same in windows 7 machine getting error
system.invalidoperationexception: specified element logical kid of element. disconnect first.
the detailed error log
[cdata[set property 'system.windows.frameworkelement.style' threw exception. loadbaml @ offset 481 in file:line:column <filename unknown>:0:0 system.invalidoperationexception: specified element logical kid of element. disconnect first. @ system.windows.frameworkelement.changelogicalparent(dependencyobject newparent) @ system.windows.frameworkelement.addlogicalchild(object child) @ system.windows.controls.contentcontrol.oncontentchanged(object oldcontent, object newcontent) @ system.windows.controls.contentcontrol.oncontentchanged(dependencyobject d, dependencypropertychangedeventargs e) @ system.windows.dependencyobject.onpropertychanged(dependencypropertychangedeventargs e) @ system.windows.frameworkelement.onpropertychanged(dependencypropertychangedeventargs e) @ system.windows.dependencyobject.notifypropertychange(dependencypropertychangedeventargs args) @ system.windows.dependencyobject.updateeffectivevalue(entryindex entryindex, dependencyproperty dp, propertymetadata metadata, effectivevalueentry oldentry, effectivevalueentry& newentry, boolean coercewithdeferredreference, boolean coercewithcurrentvalue, operationtype operationtype) @ system.windows.stylehelper.applystyleortemplatevalue(frameworkobject fo, dependencyproperty dp) @ system.windows.stylehelper.invalidatecontainerdependents(dependencyobject container, frugalstructlist`1& exclusioncontainerdependents, frugalstructlist`1& oldcontainerdependents, frugalstructlist`1& newcontainerdependents) @ system.windows.stylehelper.dostyleinvalidations(frameworkelement fe, frameworkcontentelement fce, style oldstyle, style newstyle) @ system.windows.stylehelper.updatestylecache(frameworkelement fe, frameworkcontentelement fce, style oldstyle, style newstyle, style& stylecache) @ system.windows.frameworkelement.onstylechanged(dependencyobject d, dependencypropertychangedeventargs e) @ system.windows.dependencyobject.onpropertychanged(dependencypropertychangedeventargs e) @ system.windows.frameworkelement.onpropertychanged(dependencypropertychangedeventargs e) @ system.windows.dependencyobject.notifypropertychange(dependencypropertychangedeventargs args) @ system.windows.dependencyobject.updateeffectivevalue(entryindex entryindex, dependencyproperty dp, propertymetadata metadata, effectivevalueentry oldentry, effectivevalueentry& newentry, boolean coercewithdeferredreference, boolean coercewithcurrentvalue, operationtype operationtype) @ system.windows.dependencyobject.setvaluecommon(dependencyproperty dp, object value, propertymetadata metadata, boolean coercewithdeferredreference, boolean coercewithcurrentvalue, operationtype operationtype, boolean isinternal) @ system.windows.dependencyobject.setvalue(dependencyproperty dp, object value) @ system.windows.baml2006.wpfknownmemberinvoker.setvalue(object instance, object value) @ ms.internal.xaml.runtime.clrobjectruntime.setvalue(xamlmember member, object obj, object value) @ ms.internal.xaml.runtime.clrobjectruntime.setvalue(object inst, xamlmember property, object value)]]
i have no thought element xaml or code behind causing issue. help find out reason unusual issue?
finally able find reason error have togglebutton style in application defined in app.xaml this
<style x:key="onstatelabellib" targettype="label"> <setter property="background" value="#a1a1a1"></setter> <setter property="foreground" value="black"></setter> <setter property="margin" value="0"></setter> <setter property="padding" value="0"></setter> <setter property="cursor" value="hand"/> <setter property="width" value="45"></setter> <setter property="verticalcontentalignment" value="center"></setter> <setter property="horizontalcontentalignment" value="center"></setter> <setter property="fontsize" value="14"/> <setter property="fontfamily" value="arial"/> </style> <style x:key="offstatelabellib" targettype="label"> <setter property="cursor" value="hand"/> <setter property="margin" value="0"></setter> <setter property="padding" value="0"></setter> <setter property="fontsize" value="14"/> <setter property="fontfamily" value="arial"/> <setter property="fontweight" value="extralight"/> <setter property="foreground" value="#515151"></setter> <setter property="background" value="#393939"></setter> <setter property="width" value="45"></setter> <setter property="borderbrush" value="#a1a1a1"></setter> <setter property="borderthickness" value="2"></setter> <setter property="verticalcontentalignment" value="center"></setter> <setter property="horizontalcontentalignment" value="center"></setter> </style> <style x:key="onofftogglestylelib" targettype="togglebutton" > <setter property="verticalalignment" value="center"></setter> <setter property="width" value="90"></setter> <setter property="template"> <setter.value> <controltemplate targettype="togglebutton"> <contentpresenter verticalalignment="center" /> <controltemplate.triggers> <trigger property="ismouseover" value="true"> <setter property="background" value="transparent"> </setter> </trigger> </controltemplate.triggers> </controltemplate> </setter.value> </setter> <style.triggers> <trigger property="ischecked" value="true"> <setter property="content"> <setter.value> <dockpanel margin="0"> <label dockpanel.dock="left" style="{staticresource resourcekey=onstatelabellib}" >yes</label> <label style="{staticresource resourcekey=offstatelabellib}" >no</label> </dockpanel> </setter.value> </setter> </trigger> <trigger property="ischecked" value="false"> <setter property="content"> <setter.value> <dockpanel margin="0"> <label dockpanel.dock="left" style="{staticresource resourcekey=offstatelabellib}">yes</label> <label style="{staticresource resourcekey=onstatelabellib}" >no</label> </dockpanel> </setter.value> </setter> </trigger> </style.triggers> </style>
and utilize toggle button in 2 pages page1.xaml , page2.xaml
<togglebutton margin="5" grid.row="0" tooltip="{binding path=localresource.reader_tooltip_settings_fullscreen,source={staticresource dbooklanguagemanagerdynamic}}" grid.column="1" name="btn_fullscreen" click="btn_fullscreen_clicked" style="{staticresource resourcekey=onofftogglestylelib}" />
application loads page1.xaml first , while navigating page2.xaml ma getting above exception .
now can 1 help solve this?
try changing content
property setter contenttemplate
, , using datatemplate
value:
<style x:key="onofftogglestylelib" targettype="togglebutton"> <setter property="verticalalignment" value="center"></setter> <setter property="width" value="90"></setter> <setter property="template"> <setter.value> <controltemplate targettype="togglebutton"> <contentpresenter verticalalignment="center" /> <controltemplate.triggers> <trigger property="ismouseover" value="true"> <setter property="background" value="transparent"> </setter> </trigger> </controltemplate.triggers> </controltemplate> </setter.value> </setter> <style.triggers> <trigger property="ischecked" value="true"> <setter property="contenttemplate"> <setter.value> <datatemplate> <stackpanel orientation="horizontal"> <label dockpanel.dock="left" style="{staticresource resourcekey=onstatelabellib}">yes</label> <label style="{staticresource resourcekey=offstatelabellib}">no</label> </stackpanel> </datatemplate> </setter.value> </setter> </trigger> <trigger property="ischecked" value="false"> <setter property="contenttemplate"> <setter.value> <datatemplate> <stackpanel orientation="horizontal"> <label dockpanel.dock="left" style="{staticresource resourcekey=offstatelabellib}">yes</label> <label style="{staticresource resourcekey=onstatelabellib}">no</label> </stackpanel> </datatemplate> </setter.value> </setter> </trigger> </style.triggers> </style>
i swapped dockpanel
stackpanel
, it's improve approach in opinion. allow me know if works :)
.net wpf xaml windows-runtime
No comments:
Post a Comment