c# - 如何动态绑定集合中的枚举值?(WPF)
问题描述
我正在尝试为 Exam_Room 类编写一个 DataTemplate。在这个类中有一个列表,包含名为 Exam_type 的枚举值。我尝试通过使用 ItemsControl 并将列表作为 ItemsSource 来执行此操作,但我无法实现枚举值(请参见下面的代码。
班级:
class Examination_Room : Room
{
public int id { get; set; }
public string name { get; set; }
public List<Examination_Types> types { get; set; }
public List<Waiting_Room> possible_Waiting_Rooms { get; }
}
枚举:
public enum Examination_Types
{
CR,
CT,
MG,
MR,
NM,
OT,
US,
USM
}
到目前为止的数据模板:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CAS_KAO">
<DataTemplate DataType="{x:Type local:Examination_Room}">
<Border x:Name="examination_room" Margin="10" BorderBrush="Black" BorderThickness="2">
<StackPanel Orientation="Vertical">
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock FontSize="20" FontWeight="Bold" Text="Examination room: "/>
<TextBlock FontSize="20" FontWeight="Bold" Name="room_name" Text="{Binding name}"/>
</StackPanel>
<Separator/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Examination Types: "/>
<ItemsControl ItemsSource="{Binding types}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding *****}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
到目前为止,这是我的解决方案,但正如您在代码中看到的,标有 5 星,我不知道如何访问枚举的值。(注意:截至目前,数据模板仅在没有整个考试类型的情况下进行了测试)
解决方案
推荐阅读
- c# - Microsoft.Toolkit.Uwp.UI.Controls 在将项目更新到 Fall Creators Update 时发出警告 - Visual Studio UWP
- vue.js - vue-router 在路由后无法从组件中识别 $ref
- python - 从扩展名之前的文件名中删除日期
- database - Powershell 文件数据库与驱动器号变量输入的比较
- c# - WPF、UWP 和硬件
- angular - 如何在编译期间替换字符串
- git - VSTS 不应触发合并/提交构建,NO_CI
- ios - 无法使用 Swift 从 UIViewController 访问自定义视图
- c++ - 各种库的 C++ 从 Linux 到 Windows 的交叉编译问题
- python - SSH.Paramiko.Command 执行失败