个人随笔,随时更新
ComboBox
设置选择项的值:
1:(根据内存去查找项)
ComBox_Name.SelectedItem = x(0~n);
获取选择项的值:
x = (ComBox_Name.SelectedItem as 选择项所使用的列表).某一项
这样就把选择项的值设为了选择项所使用的列表的某一项。
2:(直接设置项)
ComBox_Name.SelectedIndex = (0~n)
例:
前台:
x:Name=“combox_min”
Background=“Gray” Style=“{StaticResource ComboBoxHealth}”
Height=“20” MaxDropDownHeight=“120”
ItemsSource=“{Binding TimeTemplates}”
DisplayMemberPath=“Time”
SelectedValuePath=“ID”
VerticalContentAlignment=“Center” BorderThickness=“0”
Margin=“0,0,5,0” SelectionChanged=“combox_min_SelectionChanged”>
Set:
combox_light.SelectedItem = HelthDataViewModel.Instance.LightTemplates.First(i => i.LightMul == TosBtUtils.LightAlertCount);
Get:
TosBtUtils.LightAlertCount = (int)(combox_light.SelectedItem as HelthDataViewModel.LightTemplate).LightMul;
列表:
public class Imagemodel
{
public int ID { get; set; }
public int Model { get; set; }
}
public List<Imagemodel> LightTemplates{ get; }
void InitLightTemplates()
{
LightTemplates.Add(new LightTemplate { LightID = 1, LightMul = 10 });
LightTemplates.Add(new LightTemplate { LightID = 2, LightMul = 20 });
}
需要在页面show前把list加载进去:
如:在load
LightTemplates= new List();
InitLightTemplates();
用户控件 依赖属性绑定:
https://blog.csdn.net/qq_29198233/article/details/107833435