林已如下因素WPF窗口:組合框綁定源
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ports="clr-namespace:System.IO.Ports;assembly=System"
Title="MainWindow"
SizeToContent="WidthAndHeight">
<Window.Resources>
<ObjectDataProvider x:Key="portNames"
MethodName="GetPortNames"
ObjectType="{x:Type ports:SerialPort}" />
</Window.Resources>
<ComboBox Name="cbox" ItemsSource="{Binding Source={StaticResource portNames}}" SelectionChanged="ComboBox_SelectionChanged" />
</Window>
我米使用ObjectDataProvider的填充COM端口組合框。 但我不知道如何填充其他組合框。使用 C#功能:
private void LoadBaudRates()
{
cboxBaudRate.DataContext = new int[] { 9600, 14400, 19200, 38400, 57600, 115200, 128000 };
cboxBaudRate.SelectedIndex = 0;
}
private void LoadParity()
{
cboxParity.DataContext = Enum.GetValues(typeof(Parity));
}
private void LoadFlowControl()
{
cboxFlowControl.DataContext = Enum.GetValues(typeof(Handshake));
}
private void LoadCOMPorts()
{
var comPorts = SerialPort.GetPortNames();
//cboxCOMPorts.DataContext = comPorts;
this.cboxCOMPorts.DataContext = comPorts;
}
還有什麼其他的組合框? –
@DaniDărăban,你的意思是在XAML中? – dkozl
我有4個組合框,我設法填充Com端口,但其他3我不知道如何填充它們,是即時通訊xml代碼 –