WPF 笔记
// Command传参1
Command="{Binding VoltageCollectionCommand}" CommandParameter="{Binding ElementName=VoltageCellection,Path=IsChecked}"/>
// Command传参2
Command="{Binding OpenMsg}" CommandParameter="Warm"
<Label Content="{Binding CC1,StringFormat=\{0\} V}" Width="120"/>
数据绑定
// 绑定元素属性 <TextBox x:Name="tb" Text="{Binding ElementName=sld,Path=Value}"/> <Slider x:Name="sld" Grid.Row="2" Value="50" Maximum="100" Minimum="0"></Slider>
// 指定查找数据源
<CheckBox IsChecked="{Binding Path=IsSelected,UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Center" HorizontalAlignment="Center"
Command="{Binding Path=DataContext.SelectMenuItemCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}"/>
Invoke使用
Dispatcher.Invoke((Action)(() => { Thread.Sleep(1000); Console.WriteLine("Invoke1"); }));
comboBox
IsEditable="True" 可编辑
DisplayMemberPath="Name" 显示属性 数据源为数据模型集合(ObservableCollection<DataModel>)时使用
TabControl
TabStripPlacement="Bottom" 标签靠下
鼠标点击事件触发
<Grid.InputBindings> <MouseBinding MouseAction="LeftClick" Command="{Binding LeftClickSelectedCommand}"/> <MouseBinding MouseAction="RightClick" Command="{Binding RightClickSelectedCommand}"/> </Grid.InputBindings>
| LeftClick | 1 |
单击鼠标左键。 |
| LeftDoubleClick | 5 |
双击鼠标左键。 |
| MiddleClick | 3 |
单击鼠标中键。 |
| MiddleDoubleClick | 7 |
双击鼠标中键。 |
| None | 0 |
无操作。 |
| RightClick | 2 |
单击鼠标右键。 |
| RightDoubleClick | 6 |
双击鼠标右键。 |
| WheelClick | 4 |
旋转鼠标滚轮。 |
滚动条
<ScrollViewer Grid.Column="0" x:Name="scr" Margin="0" VerticalScrollBarVisibility="Auto"> <WrapPanel Name="rongqi"/> </ScrollViewer>
["00","01","02","03","04","05","06","07","08","09","10","11","12"], ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"],
ComboBox 自定义数据源
public class ComType { public int ID { get; set; } public string Name { get; set; } } public class ComType_bool { public bool ID { get; set; } public string Name { get; set; } }
BatteryType = new List<ComType>() { new ComType(){ ID = 1,Name = "磷酸铁锂电池" }, new ComType(){ ID = 2,Name = "三元锂电池" }, new ComType(){ ID = 3,Name = "其他电池" } };
<ComboBox ItemsSource="{Binding BatteryType}" SelectedValue="{Binding InformationEntry.battery_type}" DisplayMemberPath="Name" SelectedValuePath="ID" Style="{StaticResource com_style}"/>
设置颜色
this.phone_check.Background = new SolidColorBrush((Color)new ColorConverter().ConvertFrom("#66FFFFFF"));
浙公网安备 33010602011771号