ItemsControl的数据绑定...绑定到当前项目不工作 [英] ItemsControl data binding... binding to the current item isn't working
问题描述
我有以下ItemsControl的网页...
I have the following ItemsControl page...
<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服务,以及个别项目采购如下(从服务端)
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!?)
没有任何人有想法,我觉得有点奇怪,这用来工作(我甚至它demo'ed到下午的)
Does anyone have ideas, I find it a bit strange that this used to work (I even demo'ed it to PM's)
推荐答案
有关数据绑定与WPF工作,你需要改变你的字段属性。
For DataBinding to work with WPF, you need to change your fields to properties.
所以变化:
[DataMember] public string Name;
到
public string _Name;
[DataMember]
public string Name
{
get { return _Name; }
set { _Name = value; }
}
边注:希望你不介意我preaching,但它不是好的做法在presentation层被引用您的数据传输类 - 你应该想想分离图层。
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.
这篇关于ItemsControl的数据绑定...绑定到当前项目不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!