Home Forums WPF controls Xceed DataGrid for WPF XmlNamespaceManager doesn’t work with DataGrid

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21712 |

    <color=”green”>The following XAML has XML that doesn’t not use namespace prefixes and the data appears in the DataGrid:</color>

    <Window
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
    xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid&#8221;
    xml:lang=”en-US”
    x:Class=”XmlNamespaceBind.Window3″
    x:Name=”Window”
    Title=”Window”
    Width=”640″ Height=”480″>
    <Window.Resources>

    <XmlDataProvider x:Key=”xmlProvider”
    XPath=”/Library/Books”>
    <x:XData>
    <Library xmlns=””>
    <Books>
    <Book>
    <isbn>1234</isbn>
    <title>Title1</title>
    </Book>
    <Book>
    <isbn>5678</isbn>
    <title>Title2</title>
    </Book>
    </Books>
    </Library>

    </x:XData>
    </XmlDataProvider>
    </Window.Resources>

    <Grid x:Name=”LayoutRoot”>
    <xcdg:DataGridControl x:Name=”grid”
    ItemsSource=”{Binding Mode=TwoWay, Source={StaticResource xmlProvider}, XPath=Book}”
    CellEditorDisplayConditions=”None”
    EditTriggers=”None”
    ReadOnly=”True”
    AutoCreateColumns=”False”
    >
    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”isbn”
    Title=”ISBN”
    IsMainColumn=”True”
    Width=”60″
    DisplayMemberBinding=”{Binding XPath=isbn}”
    />
    <xcdg:Column FieldName=”title”
    Title=”Title”
    Width=”200″
    DisplayMemberBinding=”{Binding XPath=title}”
    />
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
    </Grid>
    </Window>

    <color=”green”>This XAML has XML that uses namespace prefixes and XmlNamespaceManager and the data does not appear in the DataGrid even though an empty row is present for each Book element:</color>

    <Window
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
    xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid&#8221;
    xml:lang=”en-US”
    x:Class=”XmlNamespaceBind.Window4″
    x:Name=”Window”
    Title=”Window”
    Width=”640″ Height=”480″>
    <Window.Resources>
    <XmlNamespaceMappingCollection x:Key=”NS”>
    <XmlNamespaceMapping Prefix=”y” Uri=”http://tempuri/yellow&#8221; />
    </XmlNamespaceMappingCollection>

    <XmlDataProvider x:Key=”xmlProvider”
    XmlNamespaceManager=”{StaticResource NS}”
    XPath=”/y:Library/y:Books”>
    <x:XData>
    <y:Library xmlns:y=”http://tempuri/yellow”&gt;
    <y:Books>
    <y:Book>
    <y:isbn>1234</y:isbn>
    <y:title>Title1</y:title>
    </y:Book>
    <y:Book>
    <y:isbn>5678</y:isbn>
    <y:title>Title2</y:title>
    </y:Book>
    </y:Books>
    </y:Library>
    </x:XData>
    </XmlDataProvider>

    </Window.Resources>

    <Grid x:Name=”LayoutRoot”>
    <xcdg:DataGridControl x:Name=”grid”
    ItemsSource=”{Binding Mode=TwoWay, Source={StaticResource xmlProvider}, XPath=y:Book}”
    CellEditorDisplayConditions=”None”
    EditTriggers=”None”
    ReadOnly=”True”
    AutoCreateColumns=”False”
    >
    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”isbn”
    Title=”ISBN”
    IsMainColumn=”True”
    Width=”60″
    DisplayMemberBinding=”{Binding XPath=y:isbn}”
    />
    <xcdg:Column FieldName=”title”
    Title=”Title”
    Width=”200″
    DisplayMemberBinding=”{Binding XPath=y:title}”
    />
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
    </Grid>
    </Window>

    <color=”green”>
    Is this a bug or am I missing something?

    I have found a similar problem with Microsoft’s ListView.

    Mark

    </color>

    Imported from legacy forums. Posted by Mark (had 3640 views)

    User (Old forums)
    Member
    Post count: 23064

    Mark

    You need to set the attached property Binding.XmlNamespaceManager=”{StaticResource NS}” on your DataGridControl, that way the NamespaceManager will be used for the binding as well as the XmlDataProvider.

    You may still get problems however, as you are using DisplayMemberBinding on your column. With Microsoft’s ListView/GridView, due to the way property inheritance works, you need to explicily declare a DataTemplate with the attached property, e.g.

    <GridViewColumn.CellTemplate>
    <DataTemplate>
    <TextBlock Binding.XmlNamespaceManager=”{StaticResource NS}” Text=”{Binding XPath=y:isbn}” />
    </DataTemplate>
    </GridViewColumn.CellTemplate>

    I have not tried with the XCeed grid but presume it will do the same thing.

    Regards
    Neil

    Imported from legacy forums. Posted by nmosafi (had 284 views)

    User (Old forums)
    Member
    Post count: 23064

    Note that the above technique while it will work for a ListView does not work for the xceed grid. The exceed grid has a problem binding properly to xml that has a namespace in it.

    Imported from legacy forums. Posted by Brian (had 453 views)

    User (Old forums)
    Member
    Post count: 23064

    Just to let you know that this issue has been resolved. You can obtain the latest package <a href=”http://download3.xceedsoft.com/Packages/3.0.7326.14130/XceedComponents.exe”>here</a&gt;.

    Imported from legacy forums. Posted by Matt (had 5141 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.