2011-10-18 2 views
0

コードの背後に作成されているComboBoxのComboBoxItemをスタイルする必要があります。ここに私のコードは、これまでデリゲートのパラメータとしてコントロールを渡す方法

ComboBox cbo1 = new ComboBox();     
cbo1.IsTextSearchEnabled = true; 
cbo1.IsEditable = true; 

grid1.Children.Add(cbo1); 

cbo1.Dispatcher.BeginInvoke(new StyleComboBoxItemDelegate(ref StyleComboBoxItem(cbo1), System.Windows.Threading.DispatcherPriority.Background); 

public delegate void StyleComboBoxItemDelegate(ComboBox cbo_tostyle); 

public void StyleComboBoxItem(ComboBox cbo_tostyle) 
{ 
//code to style the comboboxitem; 
} 

だ私は、次のエラーに

1. A ref or out argument must be an assignable variable 
2. Method name expected 

を取得しています誰かが私が間違ってやっているものにのようなポインティングで私を助けることができるしてください?

多くのおかげ

答えて

1

は、これらのいずれかを使用してみてください:

cbo1.Dispatcher.BeginInvoke(
    (Action)(() => StyleComboBoxItem(cbo1)), 
    System.Windows.Threading.DispatcherPriority.Background); 

cbo1.Dispatcher.BeginInvoke(
    (Action)(() => 
    { 
     //code to style the comboboxitem; 
    }), 
    System.Windows.Threading.DispatcherPriority.Background); 
+0

スーパークール:)、ありがとう。 –

1

StyleComboBoxItem()あなたが実際にvoidへの参照を作成しようとしているref StyleComboBoxItem(...)を使用することによってので、無効「を返します」。

あなたはどちらかでした:その後、

  • スタイル別の行にコンボボックス、およびあなたはまだインライン
  • を使用できるようにLETが、それはスタイルのコンボボックスを返す StyleComboBoxItem()
  • デリゲートにスタイルのコンボボックスを供給

refは必要ありません。

+0

'refのStyleComboBoxItem(...)は'デリゲート、ない方法に関するものです。 – Enigmativity

関連する問題