WPF 解决加载顺序,Combox 增加属性,并关联text

xml 复制代码
<ComboBox x:Name="camera"  Height="17" DisplayMemberPath="DisplayText" SelectedValuePath="Value" Margin="5,5,5,5"  SelectedIndex="0"  ></ComboBox>
<TextBox Height="17"  Margin="5,5,5,5" x:Name="res_h" Text="{Binding ElementName=camera,Path=SelectedItem.Value1}" TextChanged="Calc"></TextBox>
 <TextBox Height="17"  Margin="5,5,5,5" x:Name="res_w" Text="{Binding ElementName=camera,Path=SelectedItem.Value2}"  TextChanged="Calc" ></TextBox>
<TextBox Height="17"  Margin="5,5,5,5" x:Name="vof_h" TextChanged="Calc" ></TextBox>
<TextBox Height="17"  Margin="5,5,5,5" x:Name="size" Text="{Binding ElementName=camera,Path=SelectedItem.Pixelsize}"  TextChanged="Calc"></TextBox>
csharp 复制代码
public MainWindow()
{
    InitializeComponent();
    dataGrid.DataContext = this;
    var items = new List<ComboBoxItem>
{
    new ComboBoxItem { DisplayText = "Basler ace Classic acA2000-340kc 200万", Value1 = 2046,Value2=1086,Pixelsize=0.00505},
    new ComboBoxItem { DisplayText = "Dalsa 2k线阵", Value1 = 2048,Value2=1,Pixelsize=0.014  },
    new ComboBoxItem { DisplayText = "Dalsa 4k线阵", Value1= 4096,Value2=1,Pixelsize=0.00704  },
    new ComboBoxItem { DisplayText = "Dalsa 8k线阵", Value1 = 8192,Value2=1,Pixelsize=0.0035  },
    new ComboBoxItem { DisplayText = "Dalsa 16k线阵", Value1 = 16384,Value2=1,Pixelsize=0.0035  },
};

    camera.ItemsSource = items;
csharp 复制代码
        public class ComboBoxItem
        {
            public string DisplayText { get; set; } // 显示的文本
            public object Value1 { get; set; }      // 对应的值
            public object Value2 { get; set; }      // 对应的值
            public object Pixelsize { get; set; }
        }
相关推荐
埃博拉酱14 小时前
VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传
windows·ssh·visual studio code
唐宋元明清21881 天前
.NET 本地Db数据库-技术方案选型
windows·c#
加号31 天前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql
tryCbest1 天前
Windows环境下配置pip镜像源
windows·pip
呉師傅1 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
百事牛科技1 天前
保护文档安全:PDF限制功能详解与实操
windows·pdf
一个人旅程~1 天前
如何用命令行把win10/win11设置为长期暂停更新?
linux·windows·经验分享·电脑
一个假的前端男1 天前
[特殊字符] Flutter 安装完整指南 Windows—— 2026最新版
windows·flutter
倚肆2 天前
在 Windows Docker 中安装并配置 Nginx (映射 Windows 端口与路径)
windows·nginx·docker
破无差2 天前
拯救你的C盘
windows