2012-04-29 76 views
0

我必須使用預覽文本輸入事件,我必須應用於我的應用程序中的所有組合框。我們可以創建所有組合框引用的組合框事件嗎?

例如

private void cmbClass_PreviewTextInput(object sender, TextCompositionEventArgs e) 
{ 
    cmbClass.IsDropDownOpen = true; 
} 

有反正我可以用頭(任何可能的方式),這樣我就不必鍵入我所有的組合框(總共98)預覽文本輸入?

+0

是否所有的ComboBox都具有相同的Parent? – 2012-04-29 05:41:00

+0

PreviewTextInput事件 – deception1 2012-04-29 05:55:07

回答

1

在app.xaml中創建樣式。這將適用於您的應用程序的所有組合框,但如果你想要這個特定窗口的組合框,然後把它寫在標籤<Window.Resources>

<Application.Resources> 
    <Style x:Key="key1" TargetType="ComboBox"> 
     <Setter Property="IsDropDownOpen" Value="True"/> 
    </Style> 
</Application.Resources> 

<Window.Resources> 
    ... 
</Window.Resources> 

你可以爲所有組合框分配一個公共事件。將此代碼寫入.cs文件並選擇所有組合框並將此事件分配給PreviewTextInput事件。

private void cmboxes_PreviewTextInput(object sender, TextCompositionEventArgs e) 
{ 
    ((ComboBox)sender).IsDropDownOpen = true; 
} 
+0

我似乎無法使用previewtextinput屬性,當我在xaml中使用它時 – deception1 2012-04-29 05:38:26

+0

previewtextinput不是屬性其事件。 – 2012-04-29 05:40:00

+0

感謝糾正。但我應該寫一堂課嗎?還是我完全錯了? – deception1 2012-04-29 05:42:05