Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Re: Conditional query in XML - DataBinding

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-31-2006   #1 (permalink)
Pascal Bourque
Guest


 

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
Guest


 

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)
Drew Marsh
Guest


 

Re: Conditional query in XML - DataBinding

Pascal Bourque wrote:

> 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?


Hmm, yeah that's strange. Did you try doing an explicit string conversion
in your XPath... like so:

string(Page[@Uri='PageOrders.xaml']/@ShortTitle)

Don't have time to check it out, but that should coerce the value... right
now it probably returns the attribute node instance since you're not being
explicit and so the binding architecture has no clue what to do with that.
Just a guess though, don't hold me to it!

HTH,
Drew


My System SpecsSystem Spec
Old 01-31-2006   #4 (permalink)
David Sklar
Guest


 

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   #5 (permalink)
David Sklar
Guest


 

Re: Conditional query in XML - DataBinding

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   #6 (permalink)
Pascal Bourque
Guest


 

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   #7 (permalink)
Drew Marsh
Guest


 

Re: Conditional query in XML - DataBinding

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.


Hmm... I thought the same thing initially yesterday, but I went to the SDK
to check myself and sure enough it lists Title as a dependency property[1]
for Page. I didn't actually check the bits though, so maybe the documentation
is just out of wack?

Cheers,
Drew

[1] http://windowssdk.msdn.microsoft.com...leProperty.asp
___________________________________
Drew Marsh
Chief Software Architect
Mimeo.com, Inc. - http://www.mimeo.com
Microsoft C# / WPF MVP
Weblog - http://blog.hackedbrain.com/


My System SpecsSystem Spec
Old 01-31-2006   #8 (permalink)
David Sklar
Guest


 

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
Old 01-31-2006   #9 (permalink)
Pascal Bourque
Guest


 

Re: Conditional query in XML - DataBinding

The value of Page.Title is displayed in the history drop-down when you
click the Back or Forward buttons of a Navigation application. This is
the only place I found this property to be displayed.

And indeed, WindowTitle isn't a dependency property. My guess is that
it's because this property (along with Page.WindowWidth and
Page.WindowHeight) goes through IWindowService, which is implemented by
Page but delegated to an external IWindowService implementation.

In other words, Page.Window* properties simply delegate to the main
window, so dependency properties might not be suited here.

I ended up handling the Application.Navigated event to keep the main
window title in sync with the page being displayed.

Pascal

David Sklar wrote:
> 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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formatting Conditional Format Issue Vista General 3 03-25-2008 07:52 AM
Re: If and Elseif Conditional Logic Shay Levi PowerShell 0 12-20-2007 04:05 PM
Re: If and Elseif Conditional Logic Brandon Shell [MVP] PowerShell 0 12-20-2007 03:05 PM
Conditional Copying of Files pmbasu Vista file management 2 12-09-2007 04:09 AM
Ternary conditional operator Duncan Smith PowerShell 2 09-18-2007 10:29 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51