切换选项卡后,RadGridView 标头绑定中的 ComboBox 被破坏
我在 TabControl 中有几个 Telerik RadGridView。
每个 RadGridView 都有一个包含 CheckBox 的列。该列的标题是一个 CheckBox。当用户单击标题中的复选框时,列中的复选框将相应地选中或取消选中。
复选框的选中/取消选中适用于默认选择的选项卡中的 RadGridView。
选中/取消选中在默认情况下未选择的选项卡中的任何 RadGridView 中均不起作用。当您返回到默认选择的选项卡时,它仍然有效。
我复制了标题中的复选框并将其放置在 RadGridView 上方,切换选项卡后它工作正常...如果您选中/取消选中此复选框,它将选中/取消选中网格中的所有复选框...但标题中的复选框不起作用。
如果页面加载时网格不可见,则几乎就像网格标题中复选框的绑定未应用一样......
我想知道是否有人知道如何解决这个问题。
<TablControl>
<TabItem Header="Items">
<telerik:RadGridView x:Name="GridA" AutoGenerateColumns="False" ItemsSource="{Binding MyItems}">
<telerik:RadGridView.Columns>
<telerik:GridViewBoundColumnBase>
<telerik:GridViewBoundColumnBase.Header>
<CheckBox IsChecked="{Binding ElementName=TheElementBoundToTheViewModel, Path=DataContext.SelectAllMyItems, Mode=TwoWay}" />
</telerik:GridViewBoundColumnBase.Header>
<telerik:GridViewBoundColumnBase.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected}"></CheckBox>
</DataTemplate>
</telerik:GridViewBoundColumnBase.CellTemplate>
</telerik:GridViewBoundColumnBase>
<!-- ...... other stuff ..... -->
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</TabItem>
<TabItem Header="ItemsB">
<telerik:RadGridView x:Name="GridB" AutoGenerateColumns="False" ItemsSource="{Binding MyItemsB}">
<telerik:RadGridView.Columns>
<telerik:GridViewBoundColumnBase>
<telerik:GridViewBoundColumnBase.Header>
<CheckBox IsChecked="{Binding ElementName=TheElementBoundToTheViewModel, Path=DataContext.SelectAllMyItems, Mode=TwoWay}" />
</telerik:GridViewBoundColumnBase.Header>
<telerik:GridViewBoundColumnBase.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected}"></CheckBox>
</DataTemplate>
</telerik:GridViewBoundColumnBase.CellTemplate>
</telerik:GridViewBoundColumnBase>
<!-- ...... other stuff ..... -->
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</TabItem>
</TabControl>
这是我的 ViewModel:
Public Class MyItemsVM
Inherits ViewModelBase
Private _selectAllMyItems As Boolean
Public Property MyItems As ObservableCollection(Of MyItemSelectionVM)
Public Property SelectAllMyItems As Boolean
Get
Return _selectAllMyItems
End Get
Set(ByVal value As Boolean)
_selectAllMyItems = value
For Each ivm In MyItems
ivm.IsSelected = _selectAllMyItems
Next
MyBase.RaisePropertyChangedEvent(Me, SelectAllMyItemsChanged)
End Set
End Property
Private _selectAllMyItemsB As Boolean
Public Property MyItemsB As ObservableCollection(Of MyItemSelectionVM)
Public Property SelectAllMyItemsB As Boolean
Get
Return _selectAllMyItemsB
End Get
Set(ByVal value As Boolean)
_selectAllMyItemsB = value
For Each ivm In MyItemsB
ivm.IsSelected = _selectAllMyItemsB
Next
MyBase.RaisePropertyChangedEvent(Me, SelectAllMyItemsBChanged)
End Set
End Property
Public Sub New(ByVal items As MyItemList,ByVal itemsB As MyItemList)
MyItems = New ObservableCollection(Of MyItemSelectionVM)
For Each item In items
MyItems.Add(New MyItemSelectionVM(item))
Next
MyItemsB = New ObservableCollection(Of MyItemSelectionVM)
For Each item In itemsB
MyItemsB.Add(New MyItemSelectionVM(item))
Next
End Sub
End Class
Public Class MyItemSelectionVM
Implements INotifyPropertyChanged
Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Private _isSelected As Boolean
Private _item As MyItem
Public Property MyItem As MyItem
Get
Return _item
End Get
Set(ByVal value As MyItem)
_item = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("MyItem"))
End Set
End Property
Public Property IsSelected As Boolean
Get
Return _isSelected
End Get
Set(ByVal value As Boolean)
_isSelected = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("IsSelected"))
End Set
End Property
Public Sub New(ByVal theItem As MyItem)
_item = theItem
End Sub
End Class
感谢您的帮助
-Frinny
I have several Telerik RadGridViews within a TabControl.
Each of these RadGridViews has a column with CheckBoxes in. The header for this column is a CheckBox. When the user clicks the CheckBox in the header, CheckBoxes within the column are checked or unchecked accordingly.
The checking/unchecking of the CheckBoxes works for the RadGridView in the tab that is, by default, selected.
The checking/unchecking does not work in any of the RadGridViews that are in tabs that were not selected by default. When you return to the tab that selected by default, it still works.
I took a copy of the CheckBox that is in the header and placed it above the RadGridView and it works fine after switching tabs... If you check/uncheck this CheckBox it will check/uncheck all of the CheckBoxes in the Grid...but the CheckBox in the Header doesn't work.
It's almost as if the Binding for the CheckBox in the header of the Grid not applied if the Grid is not visible when the page loads....
I was wondering if anyone knows how to get around this problem.
<TablControl>
<TabItem Header="Items">
<telerik:RadGridView x:Name="GridA" AutoGenerateColumns="False" ItemsSource="{Binding MyItems}">
<telerik:RadGridView.Columns>
<telerik:GridViewBoundColumnBase>
<telerik:GridViewBoundColumnBase.Header>
<CheckBox IsChecked="{Binding ElementName=TheElementBoundToTheViewModel, Path=DataContext.SelectAllMyItems, Mode=TwoWay}" />
</telerik:GridViewBoundColumnBase.Header>
<telerik:GridViewBoundColumnBase.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected}"></CheckBox>
</DataTemplate>
</telerik:GridViewBoundColumnBase.CellTemplate>
</telerik:GridViewBoundColumnBase>
<!-- ...... other stuff ..... -->
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</TabItem>
<TabItem Header="ItemsB">
<telerik:RadGridView x:Name="GridB" AutoGenerateColumns="False" ItemsSource="{Binding MyItemsB}">
<telerik:RadGridView.Columns>
<telerik:GridViewBoundColumnBase>
<telerik:GridViewBoundColumnBase.Header>
<CheckBox IsChecked="{Binding ElementName=TheElementBoundToTheViewModel, Path=DataContext.SelectAllMyItems, Mode=TwoWay}" />
</telerik:GridViewBoundColumnBase.Header>
<telerik:GridViewBoundColumnBase.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected}"></CheckBox>
</DataTemplate>
</telerik:GridViewBoundColumnBase.CellTemplate>
</telerik:GridViewBoundColumnBase>
<!-- ...... other stuff ..... -->
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</TabItem>
</TabControl>
This is my ViewModel:
Public Class MyItemsVM
Inherits ViewModelBase
Private _selectAllMyItems As Boolean
Public Property MyItems As ObservableCollection(Of MyItemSelectionVM)
Public Property SelectAllMyItems As Boolean
Get
Return _selectAllMyItems
End Get
Set(ByVal value As Boolean)
_selectAllMyItems = value
For Each ivm In MyItems
ivm.IsSelected = _selectAllMyItems
Next
MyBase.RaisePropertyChangedEvent(Me, SelectAllMyItemsChanged)
End Set
End Property
Private _selectAllMyItemsB As Boolean
Public Property MyItemsB As ObservableCollection(Of MyItemSelectionVM)
Public Property SelectAllMyItemsB As Boolean
Get
Return _selectAllMyItemsB
End Get
Set(ByVal value As Boolean)
_selectAllMyItemsB = value
For Each ivm In MyItemsB
ivm.IsSelected = _selectAllMyItemsB
Next
MyBase.RaisePropertyChangedEvent(Me, SelectAllMyItemsBChanged)
End Set
End Property
Public Sub New(ByVal items As MyItemList,ByVal itemsB As MyItemList)
MyItems = New ObservableCollection(Of MyItemSelectionVM)
For Each item In items
MyItems.Add(New MyItemSelectionVM(item))
Next
MyItemsB = New ObservableCollection(Of MyItemSelectionVM)
For Each item In itemsB
MyItemsB.Add(New MyItemSelectionVM(item))
Next
End Sub
End Class
Public Class MyItemSelectionVM
Implements INotifyPropertyChanged
Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Private _isSelected As Boolean
Private _item As MyItem
Public Property MyItem As MyItem
Get
Return _item
End Get
Set(ByVal value As MyItem)
_item = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("MyItem"))
End Set
End Property
Public Property IsSelected As Boolean
Get
Return _isSelected
End Get
Set(ByVal value As Boolean)
_isSelected = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("IsSelected"))
End Set
End Property
Public Sub New(ByVal theItem As MyItem)
_item = theItem
End Sub
End Class
Thanks for your help
-Frinny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过为视图模型创建静态资源解决了这个问题。绑定到静态资源而不是元素的 DataContext 解决了该问题。
I solved the problem by creating a Static Resource for the View Model. Binding to the Static Resource instead of an element's DataContext fixed the problem.