我有一個日曆,我在日曆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
檢查答案。 –