2011-03-08 92 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

相關問題