WPF - 使用C#以编程方式关闭RadPane

时间:2015-03-24 18:23:54

标签: c# wpf mvvm telerik

我想以编程方式关闭RadPane。如何获取当前的RadPane以及如何触发关闭事件?

 <telerik:RadButton Content="Close" x:Name="button4" Command="{Binding ClosePaneCommand}" />   

 public ICommand ClosePaneCommand
    {
        get
        {
            return new RelayCommand(ClosePaneExecute);
        }
    }

我做了一些研究并提出了以下代码。

 RadPaneGroup container = App.Current.MainWindow.FindName(ContentContainerName) as RadPaneGroup;

        foreach (RadPane pane in container.Items)
        {
            if (pane.Content.GetType() == typeof(ScrollViewer))
            {
                ScrollViewer scrollViewer = pane.Content as ScrollViewer;
                if (scrollViewer.Content.GetType().BaseType == typeof(UserControl))
                {
                    UserControl control = scrollViewer.Content as UserControl;
                    ContentViewModel contentViewModel = control.DataContext as ContentViewModel;
                    //Here is my Question
                    if (contentViewModel == viewModel)
                    {
                        pane.RemoveFromParent();
                        break;
                    }
                }
            }
        }

我们如何比较这两个ViewModel以及如何获取当前的ViewModel?

 if (contentViewModel == viewModel)
{
}

1 个答案:

答案 0 :(得分:0)

好吧,我们可以这样删除。

 RadPaneGroup container = App.Current.MainWindow.FindName(ContentContainerName) as RadPaneGroup;

foreach (RadPane pane in container.Items)
 {
  if (pane.IsActive)
  {
    pane.RemoveFromParent();
    break;
  }
 }