我已經使用的方法,串[]計數被傳遞到組合框,但字符串[]值不是
public static string[] getMyStrings()
並將其傳遞給像的組合框:
cmbMyBox.itemsSource = getMyStrings(). //(more detail below)
調試器顯示字符串已被添加到組合框,但是當我查看組合框時,條目的數量在那裏,但空白。任何人都知道我在做什麼錯了?
我的設備列表:
public static string[] GetMIDIInDevices()
{
//get list of devices
string[] returnDevices = new string[MidiIn.NumberOfDevices];
// Get the product name for each device found
for (int device = 0; device < MidiIn.NumberOfDevices; device++)
{
returnDevices[device] = MidiIn.DeviceInfo(device).ProductName;
}
return returnDevices;
}
簡單的代碼在WPF我的主窗口上顯示:
public MainWindow()
{
InitializeComponent();
cmbMidiDropdown.ItemsSource = NAudioMIDI.GetMIDIInDevices();
//LoadMidiInDevicesIntoComboBox();
}
這裏的XAML:
<TabItem Header="MIDI Settings" Name="tabMidiSettings" Background="DarkGoldenrod">
<Grid Background="Honeydew">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="758" />
</Grid.ColumnDefinitions>
<ComboBox Grid.Column="1" Height="23" HorizontalAlignment="Right" Margin="0,141,146,0" Name="cmbMidiDropdown" VerticalAlignment="Top" Width="312" ItemsSource="{Binding}" DisplayMemberPath="Name" />
<Label Content="Select Midi Input device" Grid.Column="1" Height="28" HorizontalAlignment="Left" Margin="143,141,0,0" Name="label1" VerticalAlignment="Top" />
</Grid>
</TabItem>
調試器輸出:
GetMIDIInDevices()
- returnDevices {string[3]} string[]
[0] "MIDISPORT 2x2 In A" string
[1] "MIDISPORT 2x2 In B" string
[2] "Turtle Beach USB MIDI 1x1" string
returnDevices[device] "Turtle Beach USB MIDI 1x1" string
cmbMIDIDropdown
請顯示幾個實際的字符串值,可能有一些特殊符號 – sll 2012-02-21 16:54:44
我的猜測是你有你的XAML綁定是不正確的。你可以發佈你的XAML嗎? – 2012-02-21 16:55:08
看起來很好,因爲設備的'ProductName'實際上包含任何內容,所以您可能需要檢查它。如上所述,您的XAML可能也是錯誤的。 – 2012-02-21 16:59:49