Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[BUG]XPath or Path& Binding by Binding

20 views
Skip to first unread message

sa.c...@gmail.com

unread,
Oct 7, 2005, 7:08:45 AM10/7/05
to
1)if you try {Binding XPath=@x,Converter={StaticResource...}}
in Converter you get "string"(Value of attribute) not XmlAttribute
itself-someone already partially convert XmlAttribute;-)But if you try
Path=Attributes[x] all works as expected.

2)try
{Binding
ElementName=vb,Path=ActualWidth,Mode=OneWay,Converter={StaticResource
...},ConverterParameter={Binding
ElementName=zz1,Path=Width,Mode=OneTime}}

If Width value of zz1 already binded to another "Binding" expression
you'll get "System.Data.Binding" instead of "Double" in
ConverterParameter-strange...I wanted value of property but not
mechanism it's coming from.

Regards.

Karsten Januszewski [MS]

unread,
Oct 7, 2005, 1:37:50 PM10/7/05
to
Can you log this at http://lab.msdn.microsoft.com/productfeedback/

Thanks,
Karsten

<sa.c...@gmail.com> wrote in message
news:1128683325.2...@f14g2000cwb.googlegroups.com...

Drew Marsh

unread,
Oct 7, 2005, 1:53:28 PM10/7/05
to
sa.ce...@gmail.com wrote:

> 1)if you try {Binding XPath=@x,Converter={StaticResource...}}
> in Converter you get "string"(Value of attribute) not XmlAttribute
> itself-someone already partially convert XmlAttribute;-)But if you try
> Path=Attributes[x] all works as expected.

I just wanted to weigh in with my opinion that this one seems to work exactly
how I would expect.

I would expect the XPath statement to evaluate and give me the value of the
attribute back according to XPath semantics. Imagine you had written XPath=boolean(@x)
instead. Wouldn't you expect a boolean value? The fact that you can get at
the underlying DOM XmlAttribute instance via the Path approach is actually
awesome because it gives you exactly what you want without tainting the XPath
approach.

Just my 2¢,
Drew


Namita Gupta[MSFT]

unread,
Oct 7, 2005, 8:57:07 PM10/7/05
to
1) is by design as Drew states in his reply.

2) ConverterParameter is not a DependencyProperty and hence not
databindable. It can only be set to a literal. If you try to set it to a
Binding, the value of the Converter is set to the Binding, since it does not
support expressions which would help to evaluate the Binding. This is a
feature we decided not to support in V1. A work around for this would be to
use MultiBinding and MultiValueConverter which would let you provide more
than one bindings as input to a single MultiValueConverter.

Thanks
Namita Gupta [MSFT]

<sa.c...@gmail.com> wrote in message
news:1128683325.2...@f14g2000cwb.googlegroups.com...

sa.c...@gmail.com

unread,
Oct 8, 2005, 11:31:48 AM10/8/05
to
1)OK,I understand but how about Binding to something more interesting
than Attributes[]/ChildNodes[],something like //some_element[.=1 and
some_attribute&gt 1]?I want to get node,not empty string(Value of
XmlElement) and by the way if you wrote XPath=@x,Path=Name-you'll get
"x",so binding mechanism itself understand @x as XmlNode not Value but
for converter it prefer supply Value,strange.I thought that "Value" you
get is from "default" converter but if I provide Converter myself
binding must use "raw" value for my converter.

2)I'll try MultiBinding in my scenario,as you see I want to calculate
dynamic coefficient(for proper scaling of Polyline's Thickness in my
case).

One more thing,do you have any "ordering/routing" strategy for binding
mechanism?Suppose,I've {Binding} on Width property of "zz1" element and
use {Binding ElementName=zz1,Path=Width,Mode=OneTime,Converter=...} on
other's element property.In my case I'll get NaN-Width not binded
yet,if I change to "Mode=OneWay" I'll get correct,"binded" value second
time in my converter.Is there any means to chaining Binding,include
some kind of dependency mechanism for binding ordering?

Thanks a lot.

sa.c...@gmail.com

unread,
Oct 8, 2005, 11:51:33 AM10/8/05
to
By the way,it seems there's API
inconsistency-System.Windows.Data.IMultiValueConverter and
System.ComponentModel.IValueConverter.Why different namespaces?

Best wishes.

sa.c...@gmail.com

unread,
Oct 8, 2005, 12:34:05 PM10/8/05
to
MultiBinding dosen't work in September CTP:
<MultiBinding Converter="{StaticResource ...}" Mode="OneWay">
<Binding ElementName="zz1" Path="Width"/>
<Binding ElementName="vb"
Path="ActualWidth"/>
</MultiBinding>
In my converter I get array of untyped object of unknown nature
object[] values- values[0].GetType()=object,that must be a double
IMHO.Each of separate bindings returns double as expected if used
alone.

Any ideas,what could be wrong?
Thanks.

sa.c...@gmail.com

unread,
Oct 8, 2005, 12:52:15 PM10/8/05
to
Sorry,it seems ElementName is useless in DataTemplate:
<ViewBox x:Name="vb">
<ViewBox.Resources>
<DataTemplate x:Key="LineG">
<Polyline
Stroke="{Binding XPath=@COLOR}"
StrokeThickness="{Binding
ElementName=vb,Path=ActualWidth,Mode=OneWay,Converter={StaticResource
...}}"
Points="..."/>
</DataTemplate>
</ViewBox>
</ViewBox.Resources>
throws:

Reference error: cannot find element with given name 'vb'.
BindingExpression path error: Cannot find property 'ActualWidth' on
object 'null'.
BindingExpression:Path='ActualWidth'; DataItem='null';
target element is 'Polyline' (Name=''); target property is
'StrokeThickness' (type Double);

Drew Marsh

unread,
Oct 8, 2005, 1:47:02 PM10/8/05
to
sa.c...@gmail.com wrote:

Binding's ElementName feature only searches the nearest INameScope, which
in this case is the DataTemplate. Try using RelativeSource instead. Like so:

{Binding RelativeSource=/TemplatedParent, Path=ActualWidth, Mode=OneWay,
Converter={StaticResource ...}}

HTH,
Drew
___________________________________
Drew Marsh
Chief Software Architect
Mimeo.com, Inc. - http://www.mimeo.com
Weblog - http://blog.hackedbrain.com/


sa.c...@gmail.com

unread,
Oct 9, 2005, 6:46:35 AM10/9/05
to
Thanks,Drew,but /TemplatedParent refer to element itself but I need
another,hence ElementName...

Drew Marsh

unread,
Oct 9, 2005, 12:24:44 PM10/9/05
to
sa.c...@gmail.com wrote:

> Thanks,Drew,but /TemplatedParent refer to element itself but I need
> another,hence ElementName...

Sorry, I was just going by your example. Yeah basically RelativeSource is
only going to help you work your way up through the element tree, so if you're
trying to reach out to some other random element it's not gonna help.

Good luck,

Namita Gupta[MSFT]

unread,
Oct 10, 2005, 10:19:19 PM10/10/05
to
We have a bug about this. The reason we did this in the interim was that we
needed to support IValueConverter in the core dll, but that's no longer a
requirement. This will be fixed before we ship.

Thanks
Namita[MSFT]

<sa.c...@gmail.com> wrote in message
news:1128786693....@f14g2000cwb.googlegroups.com...

0 new messages