开发者

Databinded listbox only binds first item

I have the following xml file:

<CUEShow>
  <Showtitel>example show</Showtitel>
  <Authortitel>Wouter</Authortitel>





  <Singlecues>
<Singlecue><nr>1</nr><Name>Onweer</Name></Singlecue>
<Singlecue><nr>2</nr><Name>Regen</Name></Singlecue>
<Singlecue><nr>3</nr><Name>Donder</Name></Singlecue>
<Singlecue><nr>4</nr><Name>Onweer</Name></Singlecue>
<Singlecue><nr>5</nr><Name>Regen</Name></Singlecue>
<Singlecue><nr>6</nr><Name>Donder</Name></Singlecue>
<Singlecue><nr>7</nr><Name>Onweer</Name></Singlecue>
<Singlecue><nr>8</nr><Name>Regen</Name></Singlecue>
<Singlecue><nr>9</nr><Name>Donder</Name></Singlecue>
  </Singlecues>

  <Maincues>
<Maincue><nr>1</nr><Name>Onweer</Name><Duration>Lang</Duration><Type>GO</Type></Maincue>
<Maincue><nr>2</nr><Name>Regen</Name><Duration>Lang</Duration><Type>Follow</Type></Maincue>
<Maincue><nr>3</nr><Name>Donder</Name><Duration>Lang</Duration><Type>GO</Type></Maincue>
<Maincue><nr>4</nr><Name>Onweer</Name><Duration>Lang</Duration><Type>Follow Direct</Type></Maincue>
<Maincue><nr>5</nr><Name>Regen</Name><Duration>Lang</Duration><Type>Follow</Type开发者_JAVA百科></Maincue>
<Maincue><nr>6</nr><Name>Donder</Name><Duration>Lang</Duration><Type>GO</Type></Maincue>
<Maincue><nr>7</nr><Name>Onweer</Name><Duration>Lang</Duration><Type>GO</Type></Maincue>
<Maincue><nr>8</nr><Name>Regen</Name><Duration>Lang</Duration><Type>Follow Direct</Type></Maincue>
<Maincue><nr>9</nr><Name>Donder</Name><Duration>Lang</Duration><Type>GO</Type></Maincue>
<Maincue><nr>10</nr><Name>Onweer</Name><Duration>Lang</Duration><Type>GO</Type></Maincue>
<Maincue><nr>11</nr><Name>Regen</Name><Duration>Lang</Duration><Type>Follow</Type></Maincue>
<Maincue><nr>12</nr><Name>Donder</Name><Duration>Lang</Duration><Type>GO</Type></Maincue>
<Maincue><nr>13</nr><Name>Onweer</Name><Duration>Lang</Duration><Type>Follow Direct</Type></Maincue>
<Maincue><nr>14</nr><Name>Regen</Name><Duration>Lang</Duration><Type>Follow</Type></Maincue>
<Maincue><nr>15</nr><Name>Donder</Name><Duration>Lang</Duration><Type>GO</Type></Maincue>
<Maincue><nr>16</nr><Name>Onweer</Name><Duration>Lang</Duration><Type>GO</Type></Maincue>
<Maincue><nr>17</nr><Name>Regen</Name><Duration>Lang</Duration><Type>Follow Direct</Type></Maincue>
<Maincue><nr>18</nr><Name>Donder</Name><Duration>Lang</Duration><Type>GO</Type></Maincue>
  </Maincues>

  <Mastervolume Value="75" />


</CUEShow>

I have binded the file as a data source. Now I have a listbox in which I want to show all the Maincue nodes. I went to contentsource and selected the Maincue node. I then created an itemdatatemplate in which I bind a name to a textbox, the nr to a button text but the list only shows the first maincue. See below:

alt text http://tegen-licht.nl/Screenie.png

My item datatemplate is the following:

<DataTemplate x:Key="Maincuestemplate">
        <Grid Height="30" Width="958.737" DataContext="{Binding XPath=/CUEShow/Maincues}" Margin="0">
            <Button Content="{Binding XPath=/CUEShow/Maincues/Maincue/nr}" Width="30" Style="{DynamicResource CUEStyle_Button_Inhoudknopje}" Template="{DynamicResource CUEStyle_Knopje_Cuelijsten}" Height="Auto" HorizontalAlignment="Left" Background="#FFABCCED" DataContext="{Binding XPath=Maincue/nr}"/>
            <TextBlock Margin="58,0,0,0" Width="289.07" VerticalAlignment="Center" FontSize="16" Foreground="Gray" Text="{Binding XPath=/CUEShow/Maincues/Maincue/Name}" HorizontalAlignment="Left"/>
            <Button Width="30" Style="{DynamicResource CUEStyle_Button_Groot}" Template="{DynamicResource CUEStyle_Rondknopje}" Height="Auto" HorizontalAlignment="Right" Margin="0,0.55,74.737,-0.55" Content="u" FontFamily="Wingdings 3" Foreground="Gray" Opacity="0.4"/>
            <Button Width="30" Style="{DynamicResource CUEStyle_Button_Groot}" Template="{DynamicResource CUEStyle_Rondknopje}" Height="Auto" HorizontalAlignment="Right" Margin="0,0.55,37.071,-0.55" Content="¢" FontFamily="Wingdings 2" Foreground="Gray" Opacity="0.4"/>
            <Button Width="30" Style="{DynamicResource CUEStyle_Button_Groot}" Template="{DynamicResource CUEStyle_Rondknopje}" Height="Auto" HorizontalAlignment="Right" Margin="0" Content="Q" FontFamily="Wingdings 3" Foreground="Gray" FontWeight="Bold" FontSize="18.667" Opacity="0.4"/>
            <ProgressBar Style="{DynamicResource CUEStyle_Progressbar}" Panel.ZIndex="-1" Margin="361.93,10.833,401.737,6.527" Value="35" Template="{DynamicResource CUE_Progress}" RenderTransformOrigin="0.5,0.5">
                <ProgressBar.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleY="-1"/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform/>
                    </TransformGroup>
                </ProgressBar.RenderTransform>
            </ProgressBar>
            <TextBlock Margin="421,4.421,456.667,4.298" Width="Auto" VerticalAlignment="Stretch" FontSize="16" Foreground="Gray" Text="{Binding XPath=/CUEShow/Maincues/Maincue/Duration}" HorizontalAlignment="Stretch" d:LayoutOverrides="Height"/>
            <TextBlock Margin="0,0.55,166.667,0.718" Width="81.07" VerticalAlignment="Stretch" FontSize="21.333" Foreground="Gray" Text="{Binding XPath=/CUEShow/Maincues/Maincue/Type}" HorizontalAlignment="Right"/>
        </Grid>
    </DataTemplate>

What am I doing wrong, the binding paths seem to be correct...


When you start your XPath expression with a slash, it will work relative to the root of the document. So, regardless of the current node in the document, {Binding XPath=/CUEShow/Maincues/Maincue/nr} will evaluate to every nr node in your document. Since it wants a single node, the framework will just take the first one, and every instance of your template will use the contents of the first node.

I assume you have this DataTemplate in an ItemsControl and that the data context is a Maincue node. In that case, remove the DataContext attribute from your Grid and from your Button, since you want to use the DataContext provided by the ItemsControl, and remove the /CUEShow/Maincues/Maincue/ from each XPath expression so that you start from the current node. For example, <Button Content="{Binding XPath=nr}".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜