Telerik RadTreeListView事件绑定

时间:2013-08-02 10:56:47

标签: silverlight xaml telerik

我目前正在开发Telerik Silverlight Control,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

祝你好运 帕特里克

3 个答案:

答案 0 :(得分:0)

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

另见我的回答: https://stackoverflow.com/a/13886760/430897

答案 1 :(得分:0)

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

<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>

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

答案 2 :(得分:0)

你可以使用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]);
      }
  }