C# WPF ListView 绑定失效
写了一个ListView,XAML代码如下:<ListViewx:Name="DateList"Grid.Column="0"Margin="10,70,10,100"d...
写了一个ListView,XAML代码如下:
<ListView x:Name="DateList" Grid.Column="0" Margin="10,70,10,100" d:DataContext="{d:DesignInstance {x:Type local:DateItem}}">
<ListView.View>
<GridView>
<GridViewColumn Header="日期" Width="100" DisplayMemberBinding="{Binding Path=DateString}"/>
<GridViewColumn Header="天气" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Width="88" ItemsSource="{Binding Path=Weathers}" SelectedItem="{Binding Path=Weather}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="节日" Width="100" DisplayMemberBinding="{Binding Festival}"/>
</GridView>
</ListView.View>
</ListView>
其中绑定的类型是DateItem,其代码如下:
public class DateItem : ListViewItem
{
public string DateString { set; get; }
public string Festival { set; get; }
public string Weather { set; get; }
public DateTime Date { set; get; }
public IEnumerable<string> Weathers { set; get; }
}
实际显示时虽然列表里有Item,检查断点,列表中的DateItem各项属性也都赋值成功了,添加的Item个数也都正确,但就是没有显示绑定结果。
求问WPF大神产生这个BUG的原因是什么,怎么解决呢? 展开
<ListView x:Name="DateList" Grid.Column="0" Margin="10,70,10,100" d:DataContext="{d:DesignInstance {x:Type local:DateItem}}">
<ListView.View>
<GridView>
<GridViewColumn Header="日期" Width="100" DisplayMemberBinding="{Binding Path=DateString}"/>
<GridViewColumn Header="天气" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Width="88" ItemsSource="{Binding Path=Weathers}" SelectedItem="{Binding Path=Weather}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="节日" Width="100" DisplayMemberBinding="{Binding Festival}"/>
</GridView>
</ListView.View>
</ListView>
其中绑定的类型是DateItem,其代码如下:
public class DateItem : ListViewItem
{
public string DateString { set; get; }
public string Festival { set; get; }
public string Weather { set; get; }
public DateTime Date { set; get; }
public IEnumerable<string> Weathers { set; get; }
}
实际显示时虽然列表里有Item,检查断点,列表中的DateItem各项属性也都赋值成功了,添加的Item个数也都正确,但就是没有显示绑定结果。
求问WPF大神产生这个BUG的原因是什么,怎么解决呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询