2014-05-20 15 views
0

我有ComboBox與一個定義ComboBoxItem和一個與TextBox作爲模板。 事情是這樣的:綁定組合框與一個項目定義和一個動態

<ComboBox Grid.Column="1" Grid.Row="4" Margin="3" VerticalAlignment="Center" SelectedItem="{Binding Repeatable}"> 
     <ComboBoxItem Content="unbounded"/> 
     <ListBoxItem> 
      <ListBoxItem.Template> 
       <ControlTemplate> 
        <TextBox Text="{Binding Repeatable, Mode=TwoWay}" Width="200"/> 
       </ControlTemplate> 
      </ListBoxItem.Template> 
     </ListBoxItem> 
    </ComboBox> 

我的問題是,我不知道何爲重複字符串屬性綁定。 如果可重複=無界,我需要選擇ConboBoxItem,如果其他字符串需要填充TextBox的文本屬性。

單擊ComboBox中的任何項目時,該值必須顯示爲選中狀態。

不知道何去何從。感謝您的答案和想法。

+0

你似乎在詢問DataTriggers。我認爲這些會幫助你進一步。試試看:http://www.wpf-tutorial.com/styles/trigger-datatrigger-event-trigger/ –

+0

不知道DataTriggers如何幫助我。我需要將一個屬性綁定到兩個項目的組合框。如果屬性值等於「無界」,則選擇comboItem「unbounded」,如果其他則填充第二個ComboItem中的文本框中的值。 – Mates

+0

也許一個轉換器會幫助你。將這些屬性綁定在一起並設置一個轉換器。 –

回答

0

試試這個:

<ComboBox Text="{Binding Repeatable}" IsEditable="True"> 
     <ComboBoxItem Content="unbounded"/> 
</ComboBox> 
+0

非常感謝,這真的很有幫助,它非常簡單:) – Mates

相關問題