2011-10-18 3 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() "반환"무효, ref StyleComboBoxItem(...)를 사용하여 그래서 당신은 실제로 무효화에 대한 참조를 만들려고하고 있습니다.

당신은 수 중 하나를 여전히 인라인을 사용할 수 있도록

  • 의 스타일 별도의 행에 콤보, 그리고 그 다음이 스타일 콤보를 반환 StyleComboBoxItem() 대리인에
  • 하자를 스타일 콤보 상자 공급

ref는 필요하지 않습니다. 이들 중 하나를 사용

+0

은'REF StyleComboBoxItem (...)은'대리인 아닌 방법에 관한 것이다. – Enigmativity

관련 문제