与填充的ObservableCollection列表视图问题时, [英] Problem when filling listview with ObservableCollection
本文介绍了与填充的ObservableCollection列表视图问题时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我preSS按钮列表视图不填充。谁能帮助我?结果
公众的ObservableCollection CheckInCollection
公开的ObservableCollection< CheckInData> CheckInCollection
{
{返回_CheckInCollection; }
} 公共类CheckInData
{
公共字符串RoomNumber {搞定;组; }
公共十进制价格{搞定;组; }
公共字符串Currecny {搞定;组; }
公共小数折扣{搞定;组; }
公共字符串CheckOut的{搞定;组; }
公众诠释TotalDay {搞定;组; }
公共小数TotalPrice {搞定;组; }
公众诠释CheckOutYear {搞定;组; }
公众诠释CheckOutMonth {搞定;组; }
公众诠释CheckOutDay {搞定;组; }
公共布尔IncToday {搞定;组; }
}
私人无效btnAdd_Click(对象发件人,RoutedEventArgs E)
{
串_CheckOut =+ datePicker1.SelectedDate.Value.Day.ToString()+/+ datePicker1.SelectedDate.Value.Month.ToString()+/+ datePicker1.SelectedDate.Value.Year.ToString()+ ;
INT _TotalDays;
十进制_TotalPrice;
布尔_IncToday; 如果(cbIncToday.IsChecked ==真)
{
_IncToday = TRUE;
VAR CHECKIN =新日期时间(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day);
VAR在checkOut =新日期时间(datePicker1.SelectedDate.Value.Year,datePicker1.SelectedDate.Value.Month,datePicker1.SelectedDate.Value.Day + 1); 时间跨度TS =结算 - 签;
_TotalDays = Convert.ToInt32(ts.Days);
_TotalPrice = _TotalDays * Convert.ToDecimal(txtPrice.Text);
}
其他
{
_IncToday = FALSE;
VAR CHECKIN =新日期时间(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day);
VAR在checkOut =新日期时间(datePicker1.SelectedDate.Value.Year,datePicker1.SelectedDate.Value.Month,datePicker1.SelectedDate.Value.Day); 时间跨度TS =结算 - 签;
_TotalDays = Convert.ToInt32(ts.Days);
_TotalPrice = _TotalDays * Convert.ToDecimal(txtPrice.Text);
} _CheckInCollection.Add(新CheckInData
{
RoomNumber = cbRooms.Text,
价格= Convert.ToDecimal(txtPrice.Text)
Currecny = cbCurreny.Text,
折扣= Convert.ToDecimal(txtDiscount.Text)
CheckOut的= _CheckOut,
CheckOutYear = datePicker1.SelectedDate.Value.Year,
CheckOutMonth = datePicker1.SelectedDate.Value.Month,
CheckOutDay = datePicker1.SelectedDate.Value.Day,
IncToday = _IncToday,
TotalDay = _TotalDays,
TotalPrice = _TotalPrice });
}
XAML:
标题=检入HEIGHT =473WIDTH =682WindowStartupLocation =中心屏幕ResizeMode =NoResize的DataContext ={绑定的RelativeSource = {的RelativeSource自}} >
< ListView的保证金=8,8,5,1.04的DisplayMemberPath ={结合CheckInCollection}>
< ListView.View>
<&GridView的GT;
< GridViewColumn标题=房间号WIDTH =85DisplayMemberBinding ={结合RoomNumber}/>
< GridViewColumn标题=价格WIDTH =60DisplayMemberBinding ={结合价格}/>
< GridViewColumn标题=CurrecnyWIDTH =70DisplayMemberBinding ={结合货币}/>
< GridViewColumn标题=打折WIDTH =65DisplayMemberBinding ={结合折扣}/>
< GridViewColumn标题=退房WIDTH =100DisplayMemberBinding ={结合CheckOut的}/>
< GridViewColumn标题=总天数WIDTH =100DisplayMemberBinding ={结合TotalDays}/>
< GridViewColumn标题=总价格WIDTH =100DisplayMemberBinding ={结合TotalPrice}/>
< / GridView的>
< /ListView.View>
< /&的ListView GT;
解决方案
试试这个
< ListView的保证金=8,8,5,1.04的ItemsSource ={绑定路径= CheckInCollection UpdateSourceTrigger = PropertyChanged的}>
When i press button listview does not fills. can anyone help me?
public ObservableCollection CheckInCollection
public ObservableCollection<CheckInData> CheckInCollection
{
get { return _CheckInCollection; }
}
public class CheckInData
{
public string RoomNumber { get; set; }
public decimal Price { get; set; }
public string Currecny { get; set; }
public decimal Discount { get; set; }
public string CheckOut { get; set; }
public int TotalDay { get; set; }
public decimal TotalPrice { get; set; }
public int CheckOutYear { get; set; }
public int CheckOutMonth { get; set; }
public int CheckOutDay { get; set; }
public Boolean IncToday { get; set; }
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
string _CheckOut = "" + datePicker1.SelectedDate.Value.Day.ToString() + "/" + datePicker1.SelectedDate.Value.Month.ToString() + "/" + datePicker1.SelectedDate.Value.Year.ToString() + "";
int _TotalDays;
decimal _TotalPrice;
Boolean _IncToday;
if (cbIncToday.IsChecked == true)
{
_IncToday = true;
var checkIn = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
var checkOut = new DateTime(datePicker1.SelectedDate.Value.Year, datePicker1.SelectedDate.Value.Month, datePicker1.SelectedDate.Value.Day + 1);
TimeSpan ts = checkOut - checkIn;
_TotalDays = Convert.ToInt32(ts.Days);
_TotalPrice = _TotalDays * Convert.ToDecimal(txtPrice.Text);
}
else
{
_IncToday = false;
var checkIn = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
var checkOut = new DateTime(datePicker1.SelectedDate.Value.Year, datePicker1.SelectedDate.Value.Month, datePicker1.SelectedDate.Value.Day);
TimeSpan ts = checkOut - checkIn;
_TotalDays = Convert.ToInt32(ts.Days);
_TotalPrice = _TotalDays * Convert.ToDecimal(txtPrice.Text);
}
_CheckInCollection.Add(new CheckInData
{
RoomNumber = cbRooms.Text,
Price = Convert.ToDecimal(txtPrice.Text),
Currecny = cbCurreny.Text,
Discount = Convert.ToDecimal(txtDiscount.Text),
CheckOut = _CheckOut,
CheckOutYear = datePicker1.SelectedDate.Value.Year,
CheckOutMonth = datePicker1.SelectedDate.Value.Month,
CheckOutDay = datePicker1.SelectedDate.Value.Day,
IncToday = _IncToday,
TotalDay = _TotalDays,
TotalPrice = _TotalPrice
});
}
XAML:
Title="CheckIn" Height="473" Width="682" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" DataContext="{Binding RelativeSource={RelativeSource Self}}">
<ListView Margin="8,8,5,1.04" DisplayMemberPath="{Binding CheckInCollection}">
<ListView.View>
<GridView>
<GridViewColumn Header="Room Number" Width="85" DisplayMemberBinding="{Binding RoomNumber}"/>
<GridViewColumn Header="Price" Width="60" DisplayMemberBinding="{Binding Price}"/>
<GridViewColumn Header="Currecny" Width="70" DisplayMemberBinding="{Binding Currency}"/>
<GridViewColumn Header="Discount" Width="65" DisplayMemberBinding="{Binding Discount}"/>
<GridViewColumn Header="Check Out" Width="100" DisplayMemberBinding="{Binding CheckOut}"/>
<GridViewColumn Header="Total Days" Width="100" DisplayMemberBinding="{Binding TotalDays}"/>
<GridViewColumn Header="Total Price" Width="100" DisplayMemberBinding="{Binding TotalPrice}"/>
</GridView>
</ListView.View>
</ListView>
解决方案
try this
<ListView Margin="8,8,5,1.04" ItemsSource="{Binding Path=CheckInCollection UpdateSourceTrigger = PropertyChanged}">
这篇关于与填充的ObservableCollection列表视图问题时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文