我正在嘗試了解有關 ListView 的知識,現在我正在解決這個問題:我在后臺代碼中定義了一個列表視圖。我想動態更改 gridviewcolumn celltemplate。例如通過使用復選框或按鈕,或其他。甚至有可能嗎?我的 ListView 的定義在這里: lvUsers.ItemsSource = LoadListViewData(); GridView gridview = new GridView(); lvUsers.View = gridview; DataTemplate templateCheck = new DataTemplate(); FrameworkElementFactory factoryContentControlCheck = new FrameworkElementFactory(typeof(VsCheckBox)); factoryContentControlCheck.SetValue(VsCheckBox.MarginProperty, new Thickness(0, 0, 0, 0)); DataTemplate templateBorder = new DataTemplate(); FrameworkElementFactory factoryContentControlBorder = new FrameworkElementFactory(typeof(Border)); factoryContentControlBorder.SetValue(Border.MarginProperty, new Thickness(0, 0, 10, 0)); factoryContentControlBorder.SetValue(Border.WidthProperty, Width = 10); factoryContentControlBorder.SetValue(Border.HeightProperty, Height = 10); factoryContentControlBorder.SetValue(Border.BackgroundProperty, Brushes.Red); DataTemplate templateAge = new DataTemplate(); FrameworkElementFactory factoryContentControlAge = new FrameworkElementFactory(typeof(ContentControl)); factoryContentControlName.SetValue(ContentControl.MarginProperty, new Thickness(0, 0, 10, 0)); factoryContentControlAge.SetValue(ContentControl.VerticalAlignmentProperty, VerticalAlignment.Center); factoryContentControlAge.SetValue(ContentControl.HorizontalAlignmentProperty, HorizontalAlignment.Right); factoryContentControlAge.SetBinding(ContentControl.ContentProperty, new Binding("Age"));我想在運行時通過選中復選框或按鈕單擊將 colStack 的 CellTemplate 更改為 templateStack1。
- 1 回答
- 0 關注
- 431 瀏覽
添加回答
舉報
0/150
提交
取消