2011-03-08 99 views
1

我有以下ItemsControl的网页...ItemsControl的数据绑定...绑定到当前项目工作不

<Page x:Class="Kiosk.View.ItemListView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:Converter="clr-namespace:Kiosk.Converter" 
     mc:Ignorable="d" 
     d:DesignHeight="300" d:DesignWidth="300" 
     Margin="10" 
     Title="ItemListView"> 
    <StackPanel> 
     <Button Width="130" Height="130" Style="{StaticResource DarkButton}" 
       Command="BrowseBack" Content="Back" HorizontalAlignment="Left" Margin="0,0,0,5"/> 
     <ItemsControl ItemsSource="{Binding EventClassSummaries}"> 
      <ItemsControl.Resources> 
       <Converter:OxiStringConverter x:Key="oxiStringConverter" /> 
      </ItemsControl.Resources> 
      <ItemsControl.ItemsPanel> 
       <ItemsPanelTemplate> 
        <WrapPanel Height="1000" Width="900" Orientation="Horizontal" /> 
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <Button Content="{Binding Path=Name}" 
          Style="{StaticResource DarkButton}" 
          Height="42" 
          Width="440" 
          FontSize="12pt" 
          Margin="4"/> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 
    </StackPanel> 
</Page> 

EventClassSummaries工作正常,因为我得到的按钮,右侧数字我的总结面板,将数据从一个WCF服务采购,个别项目有(从服务端)

[DataContract] 
public class EventClassSummary 
{ 
    [DataMember] public string Category; 
    [DataMember] public char Displayed; 
    [DataMember] public int Id; 
    [DataMember] public string Name; 
    [DataMember] public char Status; 
} 

我的问题是按钮不显示Name只是结合我如下得到空白。

奇怪的是这是工作在周五,但我不得不重建服务,并添加一些额外的方法(虽然我没有触及有关这一点的人!?)

没有人有想法,我发现它有点奇怪,这曾经工作(我甚至演示了它的PM)

回答

1

对于DataBinding使用WPF,您需要将您的字段更改为属性。

因此改变:

[DataMember] public string Name; 

到:

public string _Name; 
[DataMember] 
public string Name 
{ 
    get { return _Name; } 
    set { _Name = value; } 
} 

旁注:希望你不介意我的说教,但不是很好的做法,会引用您的数据传输类在表现层 - 你应该考虑分离你的图层。

+0

不要担心,这不是最终的代码,我只是原型,但除此之外,你能解释为什么这些公共财产以前工作? – ocodo 2011-03-08 07:34:30

+1

它的确如此,我想知道为什么在添加get/set之前这是工作的。 – ocodo 2011-03-22 03:58:58