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; }
        }
相关推荐
醇氧13 小时前
WSL2(Windows Subsystem for Linux ) 从入门到实践指南
linux·运维·服务器·windows·学习
Python私教14 小时前
HermesAgent 在 Windows 原生环境安装运行指南
windows
H Journey15 小时前
Windows + VSCode + CMake 编译
windows·vscode·cmake
KivenMitnick15 小时前
CialloVOL 1.2:便捷好用的轻量化内存取证分析平台
windows·python·安全·网络安全·flask·系统安全·安全威胁分析
阿昭L15 小时前
使用内核对象进行线程同步
windows·线程同步
张赐荣16 小时前
深入详解在 Python 中用 ctypes 调用 Windows API 清空回收站
开发语言·windows·python
2501_9399982016 小时前
Antimalware Service Executable 占用率极高怎么关闭
windows
万粉变现经纪人16 小时前
如何解决 pip install bitsandbytes 报错 仅支持 Linux+glibc(macOS/Windows 失败)问题
linux·运维·windows·python·scrapy·macos·pip
嵌入式Q16 小时前
FreeRTOS源码解析(2)任务挂起与恢复
windows
Hello.Reader17 小时前
Windows C 盘空间告急?用 PowerShell 写一个安全可控的清理脚本
c语言·windows·安全