Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Re: Conditional query in XML - DataBinding

 
 
Old 01-31-2006   #1 (permalink)
Pascal Bourque


 
 

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 SpecsSystem Spec
Old 01-31-2006   #2 (permalink)
David Sklar


 
 

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 SpecsSystem Spec
Old 01-31-2006   #3 (permalink)
David Sklar


 
 

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 SpecsSystem Spec
Old 01-31-2006   #4 (permalink)
Pascal Bourque


 
 

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 SpecsSystem Spec
Old 01-31-2006   #5 (permalink)
David Sklar


 
 

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 SpecsSystem Spec
 

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46