ItemsControl data binding... binding to the current item isn't working
I have the following ItemsControl page...
<Page x:Class="Kiosk.View.ItemListView"
xmlns="http://schemas.micr开发者_运维知识库osoft.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>
The EventClassSummaries
is working correctly, as I am getting the right number of buttons in my wrap-panel, the data is sourced from a WCF service, and the individual items are as follows (from the service end)
[DataContract]
public class EventClassSummary
{
[DataMember] public string Category;
[DataMember] public char Displayed;
[DataMember] public int Id;
[DataMember] public string Name;
[DataMember] public char Status;
}
The problem I have is the Buttons do not display the Name
binding and I just get blanks.
Oddly this was working on Friday, but I've had to rebuild the service and add some additional methods (although I didn't touch the ones relevant to this!?)
Does anyone have ideas, I find it a bit strange that this used to work (I even demo'ed it to PM's)
For DataBinding to work with WPF, you need to change your fields to properties.
So change:
[DataMember] public string Name;
to:
public string _Name;
[DataMember]
public string Name
{
get { return _Name; }
set { _Name = value; }
}
Side note: Hope you don't mind me preaching, but it is not good practice to be referencing your data transfer classes in the presentation layer - you should think about separating your layers.
精彩评论