This question is locked. New answers and comments are not allowed.
Hello,
I've created a Treelistview with some dynamic columns. Each column contains a datatemplate created in code behind (I need to define a binding for each column). My datatemplate contains a customcontrol and I want to subscribe to an event defined into the custom control.
So, I haven't found any event in Page or TreelistView which will be launch after the tree view creation (template are used...). Have-you a solution or another workaround ? My current workaround is try to use the LayoutUpdated event.
Another question,do you have plan to add a new feature like fix the first column (with the treeview) ? It can help when the Treeview contains a horizontal scrollbar and many columns.
Thanks
Regards,
Florian
I've created a Treelistview with some dynamic columns. Each column contains a datatemplate created in code behind (I need to define a binding for each column). My datatemplate contains a customcontrol and I want to subscribe to an event defined into the custom control.
So, I haven't found any event in Page or TreelistView which will be launch after the tree view creation (template are used...). Have-you a solution or another workaround ? My current workaround is try to use the LayoutUpdated event.
| void MainPage_Loaded(object sender, RoutedEventArgs e) |
| { |
| ProjectServiceClient client = new ProjectServiceClient(); |
| client.GetProjectCompleted += new EventHandler<GetProjectCompletedEventArgs>(client_GetProjectCompleted); |
| client.GetProjectAsync(new GetProjectRequest()); |
| DateTime date = DateTime.Now.AddDays(-10); |
| for (int i = 0; i < dateNumber; i++) |
| { |
| date = date.AddDays(1); |
| CreateColumn(i, date); |
| dateList.Add(date); |
| } |
| } |
| public DataTemplate CreateDataTemplate(int index) |
| { |
| string xamlstring = @" |
| <DataTemplate |
| xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' |
| xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' |
| xmlns:local='clr-namespace:WorklogApplication.Controls;assembly=WorklogApplication'> |
| <Grid> |
| <local:WorklogControl Text='{Binding Path=Works[" + index + @"].ElapsedTime, Mode=OneWay}' Value='{Binding Path=Works[" + index + @"], Mode=OneWay}' /> |
| </Grid> |
| </DataTemplate>"; |
| DataTemplate dt = XamlReader.Load(xamlstring) as DataTemplate; |
| dt.LoadContent(); |
| return dt; |
| } |
| public void AddEvents() |
| { |
| List<WorklogControl> worklogs = XamlUtilities.GetChildren<WorklogControl>(workLogTree); |
| foreach (WorklogControl control in worklogs) |
| { |
| control.TextClicked -= worklog_TextClicked; |
| control.TextClicked += worklog_TextClicked; |
| control.ButtonClicked -= worklog_ButtonClicked; |
| control.ButtonClicked += worklog_ButtonClicked; |
| } |
| } |
| private void CreateColumn(int index, DateTime date) |
| { |
| RadColumn column = new RadColumn(); |
| column.Header = String.Format("{0:dd/MM}", date); |
| column.Tag = date; |
| column.CellTemplate = CreateDataTemplate(index); |
| column.Visibility = Visibility.Visible; |
| column.PropertyName = String.Format("Works[{0}]", index); |
| column.DisplayMemberPath = String.Format("Works[{0}]", index); |
| workLogTree.Columns.Add(column); |
| workLogTree.LayoutUpdated +=new EventHandler(workLogTree_LayoutUpdated); |
| } |
| void workLogTree_LayoutUpdated(object sender, EventArgs e) |
| { |
| AddEvents(); |
| } |
| List<WorkElement> BuildWorks(Project project) |
| { |
| List<WorkElement> works = new List<WorkElement>(); |
| foreach (DateTime date in dateList) |
| { |
| works.Add(new WorkElement { Date = date, ElapsedTime = project.Id + date.DayOfYear }); |
| } |
| return works; |
| } |
| void client_GetProjectCompleted(object sender, GetProjectCompletedEventArgs e) |
| { |
| ObservableCollection<Project> results = e.Result.GetProjectResult; |
| ObservableCollection<Worklog> worksCollection = new ObservableCollection<Worklog>(); |
| foreach (Project project in results) |
| { |
| worksCollection.Add(BuildWorkLog(project)); |
| } |
| workLogTree.ItemsSource = worksCollection; |
| } |
| private void worklog_TextClicked(object sender, ClickedEventArgs e) |
| { |
| Comment.Text = ""; |
| timeSlider.Value = 60; |
| } |
| private void worklog_ButtonClicked(object sender, ClickedEventArgs e) |
| { |
| RadWindow.Confirm(new DialogParameters() |
| { |
| Header = "Delete a worklog", |
| Content = "Are you sure you want to delete this worklog ?" |
| }); |
| } |
Another question,do you have plan to add a new feature like fix the first column (with the treeview) ? It can help when the Treeview contains a horizontal scrollbar and many columns.
Thanks
Regards,
Florian