的文本框的一部分,我們有一個樣式像組合框:單擊組合框
<Style x:Key="OurComboBox" TargetType="ComboBox">
<!-- omitted style Properties -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton Name="ToggleButton"
Grid.Column="2"
ClickMode="Press"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen,
Mode=TwoWay,
RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ComboBoxToggleButton}" />
<ContentPresenter Name="ContentSite"
Margin="3,3,23,3"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="False" />
<TextBox x:Name="PART_EditableTextBox"
Margin="5,3,23,1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Background="Transparent"
Focusable="False"
FontFamily="Arial Narrow"
FontWeight="DemiBold"
Foreground="#FF404040"
IsReadOnly="True"
PreviewMouseDown=""
Style="{x:Null}"
Template="{StaticResource ComboBoxTextBox}"
Text="{TemplateBinding Text}"
Visibility="Hidden" />
<!-- omitted PopUp and ControlTemplate.Triggers -->
並在此基礎上,我們還有更具體的風格
<Style x:Key="comboBoxSpecialPage"
BasedOn="{StaticResource OurComboBox}"
TargetType="ComboBox">
<Style.Triggers>
<Trigger Property="SelectedIndex" Value="-1">
<Setter Property="Text" Value="Select value" />
</Trigger>
</Style.Triggers>
</Style>
導致文本「選擇價值「如果在組合框中沒有選擇任何東西,例如在應用程序的開始。
但是,當我直接點擊文本框的文本,沒有任何反應。
所以問題是: 如何實現打開PopUp,就像當組合框(沒有文本的部分)的其餘部分被點擊一樣?
CNC中 如果我被遺漏的有趣的部分,請讓我知道,我將它們添加即可。
你真的想實現這樣的行爲?關於可用性,這是一個奇怪的解決方案,因爲您有一個用戶操作和兩個所需的行爲。如果我使用'ComboBox',我希望選擇我點擊的項目。我不希望'TextBox'切換到編輯模式。 – DHN 2013-02-18 10:45:40
我想讓ComboBox表現爲一個ComboBox。我不希望TextBox部分是可編輯的,它應該顯示一些文本。如果單擊文本框,它應該彈出組合框。現在,它沒有。如果點擊未被文本覆蓋的區域,它會彈出。我怎樣才能讓它彈出點擊文本? – 2013-02-18 11:34:29
啊,我很抱歉,現在我正在解決你的問題。 – DHN 2013-02-18 12:25:24