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 演示了它)
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>
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了使 DataBinding 能够与 WPF 一起使用,您需要将字段更改为属性。
因此,将:更改
为:
旁注:希望您不介意我说教,但在表示层中引用数据传输类并不是一个好习惯 - 您应该考虑分离各层。
For DataBinding to work with WPF, you need to change your fields to properties.
So change:
to:
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.