![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Re: Conditional query in XML - DataBinding I'm trying to do exactly that with the December CTP, and I get this exception at run-time: System.Windows.Serialization.BamlParseException was unhandled Message="Error at element 'RuntimePropertyInfo' in markup file 'PageOrders.xaml' : Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.String'.." I'm trying to bind the Page.Title property to an attribute in an XML file: <Page DataContext="{StaticResource SomeXmlFileThatDefinesMyAppPages}" ... > <Page.Title> <Binding XPath="Page[@Uri='PageOrders.xaml']/@ShortTitle" /> </Page.Title> </Page> I tried pasting the same <Binding> tag inside a <Button.Content> tag on that page and it worked. It seems that the Binding cannot auto-convert to string... I wonder if I should specify a converter in my Binding declaration? Or am I missing something? Thanks! Pascal Drew Marsh wrote: > [snip] > > The real issue for you though is gonna be the equal sign (=) because it > has special meaning inside expression syntax (Name=Value,...). So, > here's the trick... stop using the shorthand expression syntax and do > this instead: > > <WhateverYourElementIs> > <WhateverYourElementIs.Text> > <Binding XPath="/root/subitem[@id='001']"/> > </WhateverYourElementIs.Text> > </WhateverYourElementIs> > > HTH, > Drew > > |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Conditional query in XML - DataBinding No, a converter should not be necessary. I have a self-contained-XAML app in which a similarly-performed setting of <Window.Title> succeeds (December and Jan CTPs). I hereby provide that app to you in its entirety; perhaps it might help you diagnose: <Window xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"> <!-- Atlanta's weather obtained via RSS --> <Window.Resources> <XmlDataProvider x:Key='Weather' Source='http://xml.weather.yahoo.com/forecastrss?p=30350'/> </Window.Resources> <!-- This dynamically sets the window's title to display a title string extracted from the RSS feed. --> <Window.Title> <Binding Source='{StaticResource Weather}' XPath="/rss/channel/item/title"/> </Window.Title> <StackPanel> <!-- Dynamically generated label showing Atlanta's current temp: --> <Label FontSize='24'> <Label.Content> <Binding Source="{StaticResource Weather}" XPath="/rss/channel/item/*/@temp"/> </Label.Content> </Label> <!-- Static label --> <Label FontSize='24'> <Label.Content>degrees Farenheit </Label.Content> </Label> </StackPanel> </Window> |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Conditional query in XML - DataBinding Pascal: I have reproduced the problem you reported. But first note that I am not finding that Title is a useful property of Page; it seems that setting that property does not have any visual effect. And I can't repro your error via settings of that property. Instead, it appears to be the case that the property you want to use is called WindowTitle. For example: <Page...> <Page.WindowTitle>Page One</Page.WindowTitle> .... So I could only repro your error using Page.WindowTitle, and I can't explain why you were able to see the error using Page.Title. Indeed, if I set Page.WindowTitle to a non-dynamic piece of text as shown above, the page displays the title as desired. But: if I set it via a binding, it fails with the error message you reported. The issue is not related to the kind of node being pointed to by the XPath; all node types fail. And Drew's suggestion was not of value in preventing the error. I'm going to do some research into Page's WindowTitle property, how it might be different from the Title property of the Window object (for which bindings are working fine). Stay tuned... |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Conditional query in XML - DataBinding Wow, nice catch David! Thanks for taking time to investigate that matter! :-) Pascal David Sklar wrote: > No more mystery: > > Window's Title property is a dependency property, so binding works. > > Page's WindowTitle property is *not* a dependency property, so it > cannot be set dynamically via the binding mechanism. > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Conditional query in XML - DataBinding Clarification: there IS indeed a "Title" property for Page... and it is IS a dependency property... and binding is working for it (i.e. produces no runtime error) ... *BUT* it has no visual impact on the UI as far as I can tell. A page seems to get its title (for display purposes) from the "WindowTitle" property. And that property is not a dep.prop so binding is *not* working for it. Now definitely there's the possibility of a bug lurking here. The bug could be that WindowTitle should be a dep.prop. Or the bug could be that the Title property is being inadvertently ignored for display purposes. Only MSFT folks can tell us for sure... |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Conditional Formatting | Vista General | |||
| Re: If and Elseif Conditional Logic | PowerShell | |||
| If and Elseif Conditional Logic | PowerShell | |||
| Conditional Copying of Files | Vista file management | |||
| Ternary conditional operator | PowerShell | |||