2010-06-04 115 views
1

我想基於對的SelectedValue是否要啓用/禁用DataGridTextColumn鄰國DataGridComboBoxColumn ==「其他」綁定WPF DataGrid列到另一個

我可以使這項工作在下面的列表框,但這將無法在我的DataGrid環境中工作,因爲DataGridComboBox列沒有name屬性。

<ListBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Source={StaticResource CustomData}}"> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal"> 
       <ComboBox Name="operatorComboBox" SelectedValue="{Binding OperatorId}" ItemsSource="{Binding Source={StaticResource Operator}}" SelectedValuePath="Id" DisplayMemberPath="Name"></ComboBox> 
       <TextBox Text="{Binding Name}" Visibility="{Binding Path=SelectedValue, ElementName=operatorComboBox, Converter={StaticResource intToVis}}"></TextBox> 
      </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

那麼這可以用DataGrid完成嗎?

(我知道我在列表框例如改變的知名度,但它不是一個質的飛躍更改爲啓用。(顯然隱藏整列將是一件壞事,在適當的DataGrid中)

this問題與我所要求的非常相似,我只是無法將解決方案縫合到我之後

回答

1

我能想到解決此問題的最簡單方法實際上是創建DataGridTemplateColumn,而不是DataGridTextBoxColumn然後在模板內部創建一個文本框,爲了禁用/啓用文本框,將IsEnabled屬性綁定到底層的OperatorId屬性,你還必須寫一個Va檢查OperatorId值=='其他'並返回該值的lueConverter。