wpf - 在运行时为 DataGridCell 应用模板
问题描述
我想在运行时将 DataTemplate 应用于 wpf DatagridCell。
使用下面的代码,在运行时组合框出现没有数据。
<DataTemplate x:Key="cmbTemplate">
<ComboBox x:Name="cmbPicklist" ItemsSource="{Binding Picklist}" SelectedItem="{Binding PicklistSelectedItem}"/>
</DataTemplate>
<Style x:Key="MyContentStyle" TargetType="DataGridCell">
<Style.Triggers>
<DataTrigger Binding="{Binding HasPicklist}" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource cmbTemplate}"/>
</DataTrigger>
</Style.Triggers>
</Style>
在后面的代码中:
Dim oDataGridCell As DataGridCell = CType(grd_elements.Columns(0).GetCellContent(grd_elements.Items(1))?.Parent, DataGridCell)
oDataGridCell.Style = CType(oUcDatagrid.grd_layout_main.FindResource("MyContentStyle"), Style)
我想在组合框中显示数据。谁能告诉我做错了什么以及如何纠正它以使其正常工作。
解决方案
推荐阅读
- javascript - 我的网站上的平滑滚动无法正常工作
- python - 与 multiprocessing.pool 共享大型数据框
- python-3.x - 抓取工作正常,直到附加到列表
- python - 为不同的查询创建新的 SparkSession?
- pytorch - Pytorch:DataParallel 无法减少具有相同总批量大小的模型推理时间
- ember.js - Ember hasMany 关系保存在创建
- javascript - 在没有每个循环的情况下填充输入值
- python - 在 Python 中格式化字典时字典“键错误”
- airflow - 是否有任何替代终端上的“气流调度程序”命令能够在虚拟机上运行调度的 DAG 而不是“这里”?
- html - 如何从中心并排放置 Bootstrap 图像并正确调整它们的大小?