這里是以下內容。我想禁用組合框。
在視窗中的某些情況下,我只是將SelectedItemfrom設定ViewModel為某物,并且不允許用戶更改它。但在某些情況下,我想允許。
ComboBoxIsEnabled在更改VM 中的屬性時,這可以完美運行。
<ComboBox ItemsSource="{Binding MyColletionView, Mode=OneWay}"
SelectedItem="{Binding MySelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Name"
IsEnabled="{Binding MyComboBoxIsEnabled}"/>
更改屬性后ComboBox.ItemTemplate不再IsEnable反應。簡而言之,我無法禁用ComboBox.
<ComboBox ItemsSource="{Binding MyColletionView, Mode=OneWay}"
SelectedItem="{Binding MySelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding MyComboBoxIsEnabled}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource CustomerConverter}}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
我不想禁用ComboBoxItem,我想禁用ComboBoxitsef。
有什么建議,或者有人面臨同樣的問題嗎?
uj5u.com熱心網友回復:
<ComboBox Height="20" Width="200" IsEnabled="True" Margin="38,38,1682,1022" ItemsSource="{Binding SourceData}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
我按照你的描述寫了一個示例。但是我沒有使用mvvm。我想證明IsEnable和ItemTemplate之間沒有關系。您可以從以下提示中跟蹤此問題。
- 在 VisualStudio 中觀察輸出視窗。可能有一些例外。
- 用代碼隱藏替換 mvvm 并嘗試。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/413839.html
標籤:
