close
有些需求會需要全景圖橫向發展,所以會有動態產生全景圖項目(Panorama Item)的需要。 之前在這個地方卡的蠻久的,除了需要動態產生外,還需要動態Binding,才能將想要顯示的資料正確的Binding到動態產生的物件上(這邊只列出最關鍵的核心程式,如果有其它的問題可以在下方的留言板發問)。
/// 動態產生全景項目 /// private void CreatePanoramaItem(int panoramaItemCount, Panorama panorama, MainViewModel viewModel, string[] itemHeaderArray) { // 重新初始化全景圖的List變數數量 viewModel.init(itemHeaderArray.GetLength(0)); // 動態產生View控制項 for (int f = 0; f < panoramaItemCount; f++) { // ListBox ListBox listBox = new ListBox() { Margin = new Thickness(0, 0, -12, 0) }; listBox.SetBinding(ListBox.ItemsSourceProperty, new Binding("ProductItems[" + f + "]") { Source = viewModel }); listBox.SelectionChanged += ListBoxArray_SelectionChanged; listBox.ItemTemplate = Resources["listDataTemplate"] as DataTemplate; listBox.Tag = f; // 識別是第幾個listbox // 全景項目 PanoramaItem paItem = new PanoramaItem() { Content = listBox, Style = Resources["PanoramaItemStyle1"] as Style, }; //paItem.DataContext = viewModel; paItem.SetBinding(PanoramaItem.HeaderProperty, new Binding("PanoramaHeaderName[" + f + "].HeaderName") { Source = viewModel }); panorama.Items.Add(paItem); } }
全站熱搜