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; }
        }
相关推荐
mortimer19 分钟前
一次与“顽固”外部程序的艰难交锋:subprocess 调用exe踩坑实录
windows·python·ai编程
gameatp3 小时前
从 Windows 到 Linux 服务器的全自动部署教程(免密登录 + 压缩 + 上传 + 启动)
linux·服务器·windows
穷人小水滴3 小时前
在 windows 运行 flatpak 应用 (WSL)
linux·windows·ubuntu
hqwest18 小时前
C#WPF实战出真汁06--【系统设置】--餐桌类型设置
c#·.net·wpf·布局·分页·命令·viewmodel
Vae_Mars20 小时前
WPF中使用InputBindings进行快捷键绑定
wpf
hqwest1 天前
C#WPF实战出真汁05--左侧导航
开发语言·c#·wpf·主界面·窗体设计·视图viewmodel
北十南1 天前
SODA自然美颜相机(甜盐相机国际版) v9.3.0
android·windows·数码相机
nbsaas-boot1 天前
用 FreeMarker 动态构造 SQL 实现数据透视分析
数据库·windows·sql·freemarker·数据报表
weixin_446260851 天前
windows下hashcat使用gpu破解execl打开密码
windows
hqwest1 天前
C#WPF实战出真汁01--项目介绍
开发语言·c#·wpf