我在我的WPF应用程序中使用telerik radgridview
<telerik:RadTreeListView Grid.Row="1" Grid.ColumnSpan="2"
Name="WorkPreferenceTreeView"
AutoGenerateColumns="false"
IsReadOnly="True"
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Views:WorkPreferenceSelectorView}}}"
RowIndicatorVisibility="Collapsed"
SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Views:WorkPreferenceSelectorView}}}"
ScrollViewer.HorizontalScrollBarVisibility="Hidden">
<TelerikNavigation:RadContextMenu.ContextMenu>
<TelerikNavigation:RadContextMenu x:Name="RadContextMenu" />
</TelerikNavigation:RadContextMenu.ContextMenu>
<telerik:RadTreeListView.ChildTableDefinitions>
<telerik:TreeListViewTableDefinition ItemsSource="{Binding ItemPreferences}" />
</telerik:RadTreeListView.ChildTableDefinitions>
<telerik:RadTreeListView.Columns>
<telerik:GridViewDataColumn MinWidth="200" Width="*" CellTemplate="
{StaticResource ItemPreferenceskPreferenceCellTemplate}" Header="Preference" IsFilterable="false"
ShowFieldFilters="false" Name="A" />
我在控件上附加一个事件
private void InitializeControl()
{
WorkPreferenceTreeView.MouseDoubleClick += (WorkPreferenceTreeView_MouseDoubleClick);
}
现在我的问题是每当我在radtreelistview中双击ANYWHERE时(甚至在滚动条中),只要双击所选项目或行,我就会触发MouseDoubleClick事件。我想知道我是否可以在所选项目或每一行中附加MouseDoubleClick,但我没有找到方法来做到这一点。有什么建议吗?
答案 0 :(得分:0)
实际上你需要在Row上附加事件!
你可以使用 RowStyle
来完成(在此示例中,双击将切换IsExpanded行属性)
<telerik:RadTreeListView ... >
<telerik:RadTreeListView.RowStyle>
<Style TargetType="telerik:TreeListViewRow">
<EventSetter
Event="MouseDoubleClick"
Handler="HandleRowDoubleClick" />
</Style>
</telerik:RadTreeListView.RowStyle>
</telerik:RadTreeListView>
和背后的代码
public void HandleRowDoubleClick(object sender, RoutedEventArgs e)
{
var row = sender as Telerik.Windows.Controls.GridView.GridViewRow;
row.IsExpanded = !row.IsExpanded;
}
享受:)