【问题标题】:Telerik RadTreeListView Event bindingTelerik RadTreeListView 事件绑定
【发布时间】:2013-08-02 10:56:46
【问题描述】:

我目前正在开发 Telerik Silverlight 控件,即 RadTreeListView。 是否可以将 DoubleClick 事件绑定到此控件?请注意,我正在使用 MVVM 模式并且 RadTreeListView 不等于 RadTreeView 控件。 如果有人能和我分享他的经验,那就太好了。

我尝试了很多方法,但没有任何效果..

最后一个例子(看命令):

<telerik:RadTreeListView x:Name="TreeListControl" 
                             AutoGenerateColumns="False"
                             IsReadOnly="True"
                             ItemsSource="{Binding TreeViewData, ValidatesOnDataErrors=True}"
                             IsExpandedBinding="{Binding IsExpanded, Mode=TwoWay}"
                             CanUserFreezeColumns="False"
                             RowIndicatorVisibility="Collapsed"
                             ColumnWidth="*"
                             CanUserSortColumns="False"
                             evt:MouseDoubleClick.Command="{Binding DoubleCommand}"
                             >

助手类:

.... public static class MouseDoubleClick
{
    public static DependencyProperty CommandProperty =
        DependencyProperty.RegisterAttached("Command",
            typeof(ICommand),
            typeof(MouseDoubleClick),
            new PropertyMetadata(CommandChanged));

    public static DependencyProperty CommandParameterProperty =
        DependencyProperty.RegisterAttached("CommandParameter",
            typeof(object),
            typeof(MouseDoubleClick),
            new PropertyMetadata(null)); ....

编译器报错:

Error   3   The property 'Command' does not exist on the type 'RadTreeListView' in the XML namespace 'clr-namespace:CombinationTreeViewControl'.    C:\Users\B95703\Documents\Entwicklung\Silverlight\SilverlightComponents\CombinationTreeViewControl\View\CombinationTreeViewControl.xaml 32  34  CombinationTreeViewControl

最好的问候 帕特里克

【问题讨论】:

    标签: silverlight xaml telerik


    【解决方案1】:

    不要在 RegisteredAttached() 方法中使用 PropertyMetaData,而是尝试使用 UIPropertyMetaData。

    还可以在这里查看我的答案: https://stackoverflow.com/a/13886760/430897

    【讨论】:

      【解决方案2】:

      尝试在 Click 事件上的 TreeListView 上使用 System.Windows.Interactivity Triggers:

      <i:Interaction.Triggers><i:EventTrigger EventName="DoubleClick">
                      <i:InvokeCommandAction Command="{Binding DataContext.TreeViewDoubleClickCommand, ElementName=LayoutRoot}"
                                             CommandParameter="{Binding SelectedItem,ElementName=MyTreeView}"/>
                  </i:EventTrigger>
              </i:Interaction.Triggers>
      

      考虑到在 TreeListView 控件中公开了 DoubleClick 事件。

      【讨论】:

        【解决方案3】:

        可以使用RowsIsexpandedChange。扩展变化时,可以使用变量isexpand。

           private ICommand _rowIsExpandedChangedClick;
            public ICommand RowIsExpandedChangedClick
            {
        
                get
                {
                    if (_rowIsExpandedChangedClick == null)
                    {
                        _rowIsExpandedChangedClick = new MVVM.DelegateCommand<Telerik.Windows.Controls.GridView.RowEventArgs>(RowIsExpandedChangedClickShow);
                    }
        
                    return _rowIsExpandedChangedClick;
                }
                set { _rowIsExpandedChangedClick = value; }
            }
            RadTreeListView _currentRadTreeListView;
            private void RowIsExpandedChangedClickShow(Telerik.Windows.Controls.GridView.RowEventArgs e)
            {
        
                var folder = e.Row.DataContext as YourClass;
               var  row = e.Row as GridViewRow;
               _currentRadTreeListView = e.OriginalSource as RadTreeListView;
                if (row.IsExpanded)
                {
                    folder.Isexpanded = row.IsExpanded;
                }
        
        
        
            }
        
          //----------------------------------------ExpandHierarchyItem for expand specialitems
          private void collapseorexpand(FolderSarfasl _currntfolder)
          {
              if(_currntfolder.Isexpanded==true)
                  if(_currentRadTreeListView!=null)
                    _currentRadTreeListView.ExpandHierarchyItem(_currntfolder);
              for (int i = 0; i < _currntfolder.SubFolders.Count; i++)
              {
                  collapseorexpand(_currntfolder.SubFolders[i]);
              }
          }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-09-28
          • 2013-03-22
          • 1970-01-01
          • 2013-03-23
          • 1970-01-01
          相关资源
          最近更新 更多