捕获事件“单击标题组";的数据网格 [英] capture the event "click on the header group" of the datagrid

查看:78
本文介绍了捕获事件“单击标题组";的数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个Datagrid,其中有一个"ColelctionViewSource"作为"ItemSource". CollectionViewSource已经设置了"PropertyGroupDescription".对Datagrid进行分组:

< CollectionViewSource x:Key =" cvs"来源="{StaticResource art}">
 < CollectionViewSource.GroupDescriptions>
  < PropertyGroupDescription PropertyName ="GenericOri"/>
 </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

这是"GroupStyle";如您所见,它位于数据网格的扩展器"内部.可以折叠和展开组:

<!-在窗口中.参考:->
< Style x:Key =" modDGridGroupParts" TargetType ="{x:Type GroupItem}">
 < Setter属性=模板">
   < Setter.Value>
    < ControlTemplate TargetType =" {x:Type GroupItem}">
    < Expander Style =" {DynamicResource modExpanderParts}"IsExpanded =""{Binding

Items [0] .isExpanded}">
     < Expander.Header>
      < Grid>
       < Image Source =" {{Binding Items [0] .imgMarca,Converter = {StaticResource

rImgSourceConverter},模式=默认值}"/>
       < TextBlock Text =" {绑定项目[0] .BrandName}"/>
       < TextBlock Text =< {装订项目[0] .ArticleNormName}"//>
      </Grid>
     </Expander.Header>
    < ItemsPresenter/>
    </Expander>
   </ControlTemplate>
  </Setter.Value>
 </Setter>
</Style>

<!-在DataGrid中:->
< Custom:DataGrid.GroupStyle>
 < GroupStyle ContainerStyle =" {StaticResource modDGridGroupParts}>
  < GroupStyle.Panel>
   < ItemsPanelTemplate>
    < Custom:DataGridRowsPresenter x:Name ="PART_RowsPresenter"; IsItemsHost =真"/>
   </ItemsPanelTemplate>
  </GroupStyle.Panel>
 </GroupStyle>
</Custom:DataGrid.GroupStyle>

现在我有这个必要:我必须捕获扩展器扩展(或单击标题组)的事件.我必须这样做,因为我想在可视化之前修改组中的数据.我不想加载所有 从一开始就进行数据处理(这是一个太长的过程).我只想在用户单击Datagrid组的标题时才加载一些数据.我想使用Code-Behind进行此操作,因为我知道如何进行此操作.问题是捕获事件.

你能帮我吗?
谢谢!
Pileggi

解决方案

 

我必须在数据网格中执行类似的操作.我在每个标题中都有一个按钮,单击该按钮时,我必须调用一个方法.

我的团队实际上创建了一个自定义控件来扩展DataGrid.您可以捕获Expander.OnExpanded事件并调用您的方法来执行.

如果您不想创建自定义控件,我想您总是可以在后面的代码中使用下面的代码,它应该可以工作(至少我认为是这样!)

与此类似(此代码是要塞鼠标键,但可以轻松地将其修改为扩展器-

 

 受保护的 覆盖 无效  OnPreviewMouseDown   MouseButtonEventArgs  )   {   
     
或者您是否可以仅在发生扩展事件时不将命令附加到扩展器?

  希望有帮助的  


Hi,
I have a Datagrid that has a "ColelctionViewSource" as "ItemSource". The CollectionViewSource has setted a "PropertyGroupDescription" to do the grouping of the Datagrid:

<CollectionViewSource x:Key="cvs" Source="{StaticResource art}">
 <CollectionViewSource.GroupDescriptions>
  <PropertyGroupDescription PropertyName="GenericOri"/>
 </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

This is the "GroupStyle" of the datagrid, as you can see it has inside an "Expander" that allows to collapse and expand the groups:

<!-- in the Window.Reference: -->
<Style x:Key="modDGridGroupParts" TargetType="{x:Type GroupItem}">
 <Setter Property="Template">
   <Setter.Value>
    <ControlTemplate TargetType="{x:Type GroupItem}">
     <Expander Style="{DynamicResource modExpanderParts}" IsExpanded="{Binding

Items[0].isExpanded}">
      <Expander.Header>
       <Grid>
        <Image Source="{Binding Items[0].imgMarca, Converter={StaticResource

rImgSourceConverter}, Mode=Default}"/>
        <TextBlock Text="{Binding Items[0].BrandName}"/>
        <TextBlock Text="{Binding Items[0].ArticleNormName}"/>
       </Grid>
      </Expander.Header>
     <ItemsPresenter />
    </Expander>
   </ControlTemplate>
  </Setter.Value>
 </Setter>
</Style>

<!-- In the DataGrid: -->
<Custom:DataGrid.GroupStyle>
 <GroupStyle ContainerStyle="{StaticResource modDGridGroupParts}">
  <GroupStyle.Panel>
   <ItemsPanelTemplate>
    <Custom:DataGridRowsPresenter x:Name="PART_RowsPresenter" IsItemsHost="True"/>
   </ItemsPanelTemplate>
  </GroupStyle.Panel>
 </GroupStyle>
</Custom:DataGrid.GroupStyle>

Now I have this necessity: I have to capture the event of the expansion of an Expander (or the click on an header-group). I have to do this because I want to modify a bit the data in the group before they are visualized. I don't want to load all the the data from the beginning (it's a too long procedure). I want to load some data only when the user click on the header of the group of the Datagrid. I would like to do this with Code-Behind, because I know enough how to do it. The problem is to capture the event.

Can you help me?
Thank you!
Pileggi

解决方案

Hi,

 

I had to do something similar in the datagrid. I had a button in each header and when the button was clicked I had to call a method.

My team actually created a custom control that extended the DataGrid. You could capture the Expander.OnExpanded event and call your method to execute .

If you don't want to create a custom control I guess you could always use the code below in your code behind and it should work (at least I think so!)

something similar to this (this code is fort mouse button but it can easily be modidfied for the expander - 

 

 protected override void OnPreviewMouseDown(MouseButtonEventArgs e) {
         
executeyourmethodhere();
     
}

Or could you not just simply attach a command to your expander on expaned event?


Hope that helps


这篇关于捕获事件“单击标题组";的数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆