Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Binding error on XmlDataProvider (cannot bind to non-XML object)

$
0
0

Hi,

I have a problem on binding some controls to my XML.
My XAML is this (loaded at runtime):

<DataTemplate
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:EurocomCPS;assembly=EurocomCPS"><DataTemplate.Resources><local:StringToBoolConverter x:Key="StrToBoolConverter" /><local:StringToIntConverter  x:Key="StrToIntConverter" /><XmlDataProvider x:Key="dataProvider" XPath="func/parametri/param/BLOCKS"/></DataTemplate.Resources><Grid><Grid.RowDefinitions><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="100" /><ColumnDefinition Width="Auto" /></Grid.ColumnDefinitions><Label Grid.Row="0" Grid.Column="0" Content="ITEM 1:"/><Label Grid.Row="1" Grid.Column="0" Content="ITEM 2:"/><Label Grid.Row="2" Grid.Column="0" Content="ITEM 3:"/><TextBox  Grid.Row="0" 
              Grid.Column="1" 
              Text="{Binding XPath='//BLOCK[@id=1]/ITEMS/ITEM[@id=1]/@value'}" /><CheckBox Grid.Row="1" Grid.Column="1"><CheckBox IsChecked="{Binding XPath='//BLOCK[@id=1]/ITEMS/ITEM[@id=2]/@value',
                            Converter={StaticResource StrToBoolConverter}}"/></CheckBox><CheckBox Grid.Row="2" Grid.Column="1"><CheckBox IsChecked="{Binding XPath='//BLOCK[@id=1]/ITEMS/ITEM[@id=3]/@value',
                            Converter={StaticResource StrToBoolConverter}}"/></CheckBox></Grid></DataTemplate>

The xml file is this:

<func id="A29086"><parametri><param><BLOCKS max_count="2" write_id="49" read_req_id="47" read_rep_id="48" session_id="7"><BLOCK id="1" frame="1" framelen="61"><ITEMS max_count="14"><ITEM id="1" type="CHAR" size="1" value="0" /><ITEM id="2" type="CHAR" size="1" value="1" /><ITEM id="3" type="CHAR" size="1" value="0" />
            ...</ITEMS></BLOCK><BLOCK id="2" frame="1" framelen="61"><ITEMS max_count="14"><ITEM id="1" type="CHAR" size="1" value="0" /><ITEM id="2" type="CHAR" size="1" value="1" />
            ...</ITEMS></BLOCK></BLOCKS></param></parametri></func>
When running I get this error:
System.Windows.Data Error: 44 : BindingExpression with XPath cannot bind to non-XML object.; XPath='//BLOCK[@id=1]/ITEMS/ITEM[@id=1]/@value' BindingExpression:Path=/InnerText; DataItem='Tab' (HashCode=57706919); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String') Tab:'EurocomCPS.Tab'
System.Windows.Data Error: 44 : BindingExpression with XPath cannot bind to non-XML object.; XPath='//BLOCK[@id=1]/ITEMS/ITEM[@id=2]/@value' BindingExpression:Path=/InnerText; DataItem='Tab' (HashCode=57706919); target element is 'CheckBox' (Name=''); target property is 'IsChecked' (type 'Nullable`1') Tab:'EurocomCPS.Tab'
System.Windows.Data Error: 44 : BindingExpression with XPath cannot bind to non-XML object.; XPath='//BLOCK[@id=1]/ITEMS/ITEM[@id=3]/@value' BindingExpression:Path=/InnerText; DataItem='Tab' (HashCode=57706919); target element is 'CheckBox' (Name=''); target property is 'IsChecked' (type 'Nullable`1') Tab:'EurocomCPS.Tab'

Where I wrong?


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>