2015-05-04 63 views
0

我有以下SQL表結構WPF單選按鈕綁定到不同的性質

  1. DeleteOwn作爲位0或1
  2. DeleteAll作爲位0或1
  3. NoDelete作爲第0位或1

在XAML中我有以下的

      <RadioButton IsChecked="{Binding CurrentItem.Item[DeleteOwn]}" Content="Delete Own" HorizontalAlignment="Left" Margin="21,46,0,0" VerticalAlignment="Top"/> 
          <RadioButton IsChecked="{Binding CurrentItem.Item[DeleteAll]}" Content="Delete All" HorizontalAlignment="Left" Margin="21,67,0,0" VerticalAlignment="Top"/> 
          <RadioButton IsChecked="{Binding CurrentItem.Item[NoDelete]}" Content="No Delete" HorizontalAlignment="Left" Margin="21,88,0,0" VerticalAlignment="Top"/> 

這裏是我的代碼如何檢索數據:

Property MyItems As BindingListCollectionView 
Property CurrentItem As DataRowView 
Sub LoadData() 
    MyItems = CollectionViewSource.GetDefaultView(GlobalApp.GetData("select * from mytable").DefaultView) 
    NotifyProperty("MyItems") 
End Sub 

,這裏是CURRENTITEM是如何關聯的

Private Sub ChangeSelected(sender As Object, e As RoutedPropertyChangedEventArgs(Of Object)) 
      Dim MyTreeView As TreeView = DirectCast(sender, TreeView) 
      CurrentItem = MyTreeView.SelectedItem 
      NotifyProperty("CurrentItem") 
End Sub 

時到窗口加載的數據值顯示正確,但通過單擊單選按鈕更改值後綁定將丟失並顯示單選按鈕的值不正確。 我該如何使它工作?

+3

後包含CurrentItem.Item的代碼[...' –

+0

我已經更新我的問題與示例代碼,任何幫助表示讚賞 – user2160275

回答

0

我不知道這是否有助於其他人,但我能夠通過做2件事來解決它。

  • 在每個單選按鈕我要聲明3個不同的組名稱(這對我來說,這是錯誤的,但要使它工作,我沒有別的辦法),例如

        <RadioButton GroupName="a"/> 
            <RadioButton GroupName="b"/> 
            <RadioButton GroupName="c"/> 
    
  • 每次其中一個單選按鈕將狀態更改爲True時,其他單選按鈕應設置爲false,我期待此行爲開箱即用

    (當您在單選按鈕中的綁定不工作時)

但我有我的自我實現它,因爲綁定都不能正常工作,所以在後面的代碼,我把一個邏輯,當我的一個屬性更改爲True的其他屬性都設置爲False