0

我目前正在研究 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

最好的问候帕特里克

4

3 回答 3

0

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

另请参阅我的答案: https ://stackoverflow.com/a/13886760/430897

于 2013-08-03T05:26:43.173 回答
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]);
      }
  }
于 2014-02-10T10:09:34.560 回答
0

尝试在 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>

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

于 2013-08-03T09:51:50.740 回答