2017-12-12 10 views
1

私はxamarin & C#を使ってmacOSアプリケーションを開発しています。私はストーリーボードにNSComboBoxを持っています。それはコンセントを持っているので、私はそれにうまくアクセスできます。XAMARIN&C#でmacOS NSComboBoxにアイテムを追加する方法は?

私はこのようなリストに移入データコンテキスト持っている:私は、追加機能をNSComboBoxにこのリストを追加したい

public static List<string> bloomTypes_EN = new List<string>(new string[] { 
     "Cognitive Memory", 
     "Cognitive Understanding", 
     "Cognitive Practice", 
     "Cognitive Analysis", 
     "Cognitive Evaluation", 
     "Cognitive Generation", 
     "Affective Reception", 
     "Affective Behavior", 
     "Affective Valuing", 
     "Affective Organization", 
     "Affective Character Making", 
     "Psychomotor Perception", 
     "Psychomotor Organization", 
     "Psychomotor Guided Behavior", 
     "Psychomotor Mechanization", 
     "Psychomotor Complex Behavior", 
     "Psychomotor Harmony", 
     "Psychomotor Generation" }); 

を:

if(EarnArea_ComboBox.Count != 0) // If not empty. 
     { 
      EarnArea_ComboBox.RemoveAll(); // delete all items. 
     } 
     else // Empty. 
     { 
      EarnArea_ComboBox.Add(values.ToArray()); 
     } 

は、機能を追加するNSObjectのを追加サポートしています[ ]。文字列配列を与えると、次のエラーが発生します。

Error CS1503: Argument 1: cannot convert from 'string[]' to 'Foundation.NSObject[]' (CS1503)

NSComboBoxに項目を追加するにはどうすればよいですか?ありがとう。ココア(とiOS)コントロールが列/行ベースのデータを選択し、提示することを可能にするDataSource性質を持っているの

答えて

2

多くは、等...

だから NSComboBoxDataSourceサブクラスを作成し、それが List<string>内を受け入れましょう、検索しましたその.actor:

public class BloomTypesDataSource : NSComboBoxDataSource 
{ 
    readonly List<string> source; 

    public BloomTypesDataSource(List<string> source) 
    { 
     this.source = source; 
    } 

    public override string CompletedString(NSComboBox comboBox, string uncompletedString) 
    { 
     return source.Find(n => n.StartsWith(uncompletedString, StringComparison.InvariantCultureIgnoreCase)); 
    } 

    public override nint IndexOfItem(NSComboBox comboBox, string value) 
    { 
     return source.FindIndex(n => n.Equals(value, StringComparison.InvariantCultureIgnoreCase)); 
    } 

    public override nint ItemCount(NSComboBox comboBox) 
    { 
     return source.Count; 
    } 

    public override NSObject ObjectValueForItem(NSComboBox comboBox, nint index) 
    { 
     return NSObject.FromObject(source[(int)index]); 
    } 
} 

今、あなたはあなたのNSComboBoxにこれを適用することができます。

EarnArea_ComboBox.UsesDataSource = true; 
EarnArea_ComboBox.DataSource = new BloomTypesDataSource(bloomTypes_EN); 

enter image description here

+0

ありがとう:)それは実行中です.... –

+0

@BerkB。うれしかった – SushiHangover

関連する問題