我有一个日历,我在日历itemscontrol中嵌套了一个itemscontrol,以便我可以在gridcell(日期)中显示要为其生成事件的事件。压光机是7列6行。现在我只是使用列表框来实际显示事件(标题)。我可以在启动时添加项目,但我希望能够在程序已经运行时添加/删除/更改。我曾尝试过一次INotifyPropertyChanged,但我无法弄清楚它是否适合我的生活。如果某人可以拿走我拥有的东西并给我看,或者给我提示我如何做到这一点,我会非常感激。如何使用INotifyPropertyChanged更新ListBox
类,我可以启动前添加(项):
public class eventProperties : ObservableCollection<eventsTitles>
{
//public string Eventer { get; set; }
public eventProperties() : base()
{
Add(new eventsTitles("First Test"));
Add(new eventsTitles("First Test#2"));
}
这是窗口(类)时,我想一旦程序启动和运行已添加事件弹出。我需要弄清楚如何使用这个窗口,以及如何将它添加到某一特定日期(栅格单元)添加项目
public Event(MainWindow parentform)
{
InitializeComponent();
_parentForm = parentform;
//this.month = month;
//this.day = day;
//this.year = year;
lblCreateEvent.Content = "Create Event For " + month + "/" + day + "/" + year;
}
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
month = Convert.ToInt32(txtMonth.Text);
day = Convert.ToInt32(txtDay.Text);
year = Convert.ToInt32(txtYear.Text);
Schedule sched = new Schedule();
DateTime curr = DateTime.Now;
int[] m = new int[7];
DateTime newcurr = new DateTime(year, month, day);
var cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
var ms = cal.GetWeekOfYear(new DateTime(newcurr.Year, newcurr.Month, 1), System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Sunday);
// for (var i = 1; newcurr.Month == 11; newcurr = newcurr.AddDays(1))
// {
var month_week = (newcurr.Day/7);
sched.MonthWeek = newcurr.GetWeekOfMonth().ToString();
sched.Month = newcurr.Month.ToString();
sched.Year = newcurr.Year.ToString();
sched.day = newcurr.Day.ToString();
sched.WeekOfYear = cal.GetWeekOfYear(newcurr, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString();
sched.dayofweek = newcurr.DayOfWeek.ToString();
//Here is where the calender is created. By looping through all the days in the selected month it will find the weeknumber and day of the week -->
// that that particular date belongs to and place in the correct gridcell.
_parentForm.bindings.schedule.Add(new Schedule { WeekNo = newcurr.GetWeekOfMonth() - 1, WeekDay = (int)newcurr.DayOfWeek, day = newcurr.Day.ToString(), eventTitle = "Camper Calender" });
这是实际的压延XAML,我需要绑定的一切。
</customgridcontrol:GridControl>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<Button Content="{Binding day}" Width="175" HorizontalAlignment="Stretch" VerticalAlignment="Top" VerticalContentAlignment="Top" HorizontalContentAlignment="Left" Name="btnCalenderDate" Click="btnCalenderDate_Click" Loaded="btnCalenderDate_Loaded" Height="18" FontSize="10" FontWeight="Bold">
</Button>
<ItemsControl Height="60" VerticalAlignment="Stretch">
<ItemsControl.Resources>
<src:eventProperties x:Key="dataList"/>
</ItemsControl.Resources>
<ItemsControl.Items>
<ListBox ItemsSource="{Binding Source= {StaticResource dataList} }" DisplayMemberPath="EventTitle" VerticalAlignment="Top" IsSynchronizedWithCurrentItem="True">
</ListBox>
</ItemsControl.Items>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<!-- ItemContainerStyle -->
<ItemsControl.ItemContainerStyle>
<Style >
<Setter Property="Grid.Column" Value="{Binding WeekDay}" />
<Setter Property="Grid.Row" Value="{Binding WeekNo}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
eventTitles类
namespace Camp_
{
public class eventsTitles
{
public string eventTitle {get; set;}
public eventsTitles()//String ev)
{
// this.eventTitle = ev;
}
public string EventTitle
{
get { return eventTitle; }
set { eventTitle = value; }
}
}
}
你能告诉我们eventsTitles'类'的实施,这部分是小鬼的回答正确... –
肯定可以一秒。 – TMan
检查答案。 –