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; }
        }
相关推荐
路由侠内网穿透2 天前
本地部署 GPS 跟踪系统 Traccar 并实现外部访问
运维·服务器·网络·windows·tcp/ip
研华嵌入式2 天前
如何在高通跃龙QCS6490 Arm架构上使用Windows 11 IoT企业版?
arm开发·windows·嵌入式硬件
玉面小君2 天前
从 WPF 到 Avalonia 的迁移系列实战篇6:Trigger、MultiTrigger、DataTrigger 的迁移
wpf·avalonia
带娃的IT创业者2 天前
Windows 平台上基于 MCP 构建“文心一言+彩云天气”服务实战
人工智能·windows·文心一言·mcp
csdn_aspnet2 天前
Windows Node.js 安装及环境配置详细教程
windows·node.js
摇滚侠2 天前
java语言中,list<String>转成字符串,逗号分割;List<Integer>转字符串,逗号分割
java·windows·list
Source.Liu2 天前
【Pywinauto库】12.2 pywinauto.element_info 后端内部实施模块
windows·python·自动化
Source.Liu2 天前
【Pywinauto库】12.1 pywinauto.backend 后端内部实施模块
开发语言·windows·python·自动化
私人珍藏库2 天前
[Windows] FileOptimizer v17.1.0_一款文件批量压缩工具
windows·批量压缩
掘根2 天前
【CMake】List
windows·microsoft·list