Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / August 2007

Tip: Looking for answers? Try searching our database.

Binding to XPath with prefix in GridViewColumn?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim Hudson - 26 Jul 2007 21:50 GMT
I have a ListView with an ItemSource that is bound to some XML, via {Binding
Xpath=...}.  The ListView.View is defined with a GridView.  In the individual
GridViewColumn elements, I'd like to specify DisplayMemberBinding, and bind
to the various XML elements.  If my XML is specified with the default
namespace, then everyting works like a charm:

<GridViewColumn Header="Name" DisplayMemberBinding="{Binding XPath=name}" />

However, my production XML relies on several namespaces, and so my
production XML element names have a prefix.  When I change my XAML code to
use an XmlNamespaceManager, everything ELSE works with the prefixed XPaths,
except for the GridViewColumns.  Thus the following:

<GridViewColumn Header="Name" DisplayMemberBinding="{Binding
XPath=cap:name}" />

doesn't work.  Found a solution (somewhere on the Internet) that proposed
switching from DisplayMemberBinding to using a CellTemplate, but that didn't
work either.

Any other ideas?
Signature

Jim Hudson

Walter Wang [MSFT] - 27 Jul 2007 14:20 GMT
Hi Jim,

This is a quick note to let you know that I am performing research on this
issue and will get back to you as soon as possible. I appreciate your
patience.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 30 Jul 2007 08:22 GMT
Hi Jim,

I've done some research and following code works on my side:

<Window x:Class="WpfApplication1.Window1"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="Window1" Height="300" Width="300">
   <Window.Resources>
       <XmlNamespaceMappingCollection x:Key="mapping">
           <XmlNamespaceMapping Uri="http://foo" Prefix="foo" />
       </XmlNamespaceMappingCollection>

       <XmlDataProvider x:Key="Books" Source="Books.xml"
XmlNamespaceManager="{StaticResource mapping}" />
   </Window.Resources>
   <StackPanel>
       <TextBlock>ListView</TextBlock>
       <ListView>
           <ListView.ItemsSource>
               <Binding Source="{StaticResource Books}"
XPath="foo:Books/foo:Book" />
           </ListView.ItemsSource>
           <ListView.View>
               <GridView>
                   <GridViewColumn Header="Name"
DisplayMemberBinding="{Binding XPath=foo:Name}" />
               </GridView>
           </ListView.View>
       </ListView>
       <TextBlock>ListBox</TextBlock>
       <ListBox>
           <ListBox.ItemsSource>
               <Binding Source="{StaticResource Books}"
XPath="foo:Books/foo:Book"/>
           </ListBox.ItemsSource>
           <ListBox.ItemTemplate>
               <DataTemplate>
                   <TextBlock Text="{Binding XPath=foo:Name}">
                   </TextBlock>
               </DataTemplate>
           </ListBox.ItemTemplate>
       </ListBox>
   </StackPanel>
</Window>

Books.xml

<?xml version="1.0" encoding="utf-8" ?>
<foo:Books xmlns:foo="http://foo">
    <foo:Book>
        <foo:Name>First</foo:Name>
        </foo:Book>
</foo:Books>

Please test this and let me know the result. Thanks.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Jim Hudson - 03 Aug 2007 21:34 GMT
Your ListView didn't work on my machine.  I modified your code, a little, to
make sure that the ListView was doing anything.  The modified code is:

 <StackPanel>
   <TextBlock>ListView</TextBlock>
   <ListView ItemsSource="{Binding Source={StaticResource Books},
XPath=foo:Books/foo:Book}" >
     <ListView.View>
       <GridView>
         <GridViewColumn Header="Name1" DisplayMemberBinding="{Binding
XPath=foo:Name}" />
         <GridViewColumn Header="Row?" >
           <GridViewColumn.CellTemplate>
             <DataTemplate>
               <TextBlock Text="A Row" />
             </DataTemplate>
           </GridViewColumn.CellTemplate>
         </GridViewColumn>
       </GridView>
     </ListView.View>
   </ListView>
   <TextBlock>ListBox</TextBlock>
   <ListBox ItemsSource="{Binding Source={StaticResource Books},
XPath=foo:Books/foo:Book}" >
     <ListBox.ItemTemplate>
       <DataTemplate>
         <TextBlock Text="{Binding XPath=foo:Name}" />
       </DataTemplate>
     </ListBox.ItemTemplate>
   </ListBox>
 </StackPanel>

I also added 3 more <foo:Book> nodes into Books.xml.  When I run the
application, the window looks like this:

----------------------------------------
| ListView
| Name1   Row?
[quoted text clipped - 7 lines]
| Third
| Fourth
----------------------------------

Given that your code works properly on your machine, I have to conclude that
the problem is in the particular release of the .Net 3.0 WPF assemblies
installed on my computer.  

Here's where I get a little confused.  In my VS2005 project file, the
references for PresentationCore and PresentationFramework both go to dlls in
"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0".  
Those DLLs are listed as "Runtime Version v2.0.50727, Version 3.0.0.0".

However, my GAC contains different versions of the same 2 assemblies: the
GAC assemblies are marked as "Product Version 3.0.6912.0 Version 3.0.0.0"
(BTW, I'm doing this testing on a Vista Business 64-bit system).  

Have I installed out-of-date copies of the WPF/WCF Framework SDKs?

Signature

Jim Hudson

Walter Wang [MSFT] - 06 Aug 2007 04:19 GMT
Hi Jim,

After further testing, this looks like an issue of .NET Framework 3.0 but
fixed in .NET Framework 3.5 Beta 2. Please install .NET Framework 3.5 Beta
2 from here:

#Download details: .NET Framework 3.5 Beta 2
http://www.microsoft.com/downloads/details.aspx?familyid=d2f74873-c796-4e60-
91c8-f0ef809b09ee&displaylang=en

We're sorry for the inconvenience caused by this. I'll file a bug for it.

Please note the RTM version of .NET Framework 3.5 is scheduled to be
released at end of 2007; beta 2 of it is also included in VS2008 (aka
Orcas) beta 2, which can be downloaded here:
http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspx

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Jim Hudson - 06 Aug 2007 13:22 GMT
Thanks for the info, Walter.  I'll pass the word about those 2 beta versions
around here at my company.

Signature

Jim Hudson

Walter Wang [MSFT] - 07 Aug 2007 03:26 GMT
Hi Jim,

Thanks for your quick reply. Please feel free to let me know if you have
any concerns or questions about this issue.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.