1

我在我的项目中使用 Telerik RadGridView(它本质上是一个标准的 GridView)。这个组件有它自己的过滤功能,我想利用它。

我计划根据几个组合框选择的值进行过滤。因此,如果我对 MVVM 有正确的认识,我需要将组合绑定到一些 ViewModel 的属性。但是这里有一个问题,如何将这些选定的值传递回 View 的组件?如何使其在选定值更改时刷新过滤?

upd:我使用 SimpleMVVM 框架。

主窗口的 XAML:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
......
    DataContext="{Binding Source={StaticResource Locator}, Path=MainPageViewModel}">

<StackPanel Height="auto">
    <telerik:RadMenu VerticalAlignment="Top">
    ......            
    </telerik:RadMenu>
    <my:Expander VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="auto" Width="auto"/>
    <my:CustomerView Margin="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="auto" Width="auto"/>
</StackPanel>

扩展器的 XAML:

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
...... >


<Grid Margin="10,10,0,10" Width="684" Height="97" VerticalAlignment="Top" HorizontalAlignment="Left" >

    <telerik:RadExpander x:Name="radExpander" IsExpanded="True" HorizontalAlignment="Stretch" VerticalAlignment="Top" telerik:AnimationManager.IsAnimationEnabled="True" Margin="0,0,0,0" Grid.RowSpan="2">
            <telerik:RadComboBox HorizontalAlignment="Left" Margin="244,-2,0,0" VerticalAlignment="Top" Width="154" Height="26" 
                                 ItemsSource="{Binding Path=AllLevels}" DisplayMemberPath="name" SelectedItem="{Binding SelectedEventLevel}"/>
 .......

        </Grid>
    </telerik:RadExpander>
</Grid>

CustomerView 的 XAML:

       <telerik1:RadGridView Name="EventList" .... ItemsSource="{Binding SportEventsList}" AutoGenerateColumns="False">
        <telerik1:RadGridView.Columns>
 .....
        </telerik1:RadGridView.Columns>
    </telerik1:RadGridView>

Viewmodel 的代码片段:

      private ObservableCollection<sportevent> _sportEventsList;
  public ObservableCollection<sportevent> SportEventsList
  {
      get { return _sportEventsList; }
      set
      {
          _sportEventsList = value;
          NotifyPropertyChanged(vm => vm.SportEventsList);
      }
  }
4

1 回答 1

0

将以下属性添加到您的 VM:

    private ObservableCollection<yourType> allLevels;
    public ObservableCollection<yourType> AllLevels
    {
        get
        {
            return allLevels;
        }
        set
        {
            allLevels = value;
            RaisePropertyChanged("AllLevels");
        }
    }

    private yourType selectedEventLevel;
    public yourTypeSelectedEventLevel
    {
        get
        {
            return selectedEventLevel;
        }
        set
        {
            selectedEventLevel = value;
            RaisePropertyChanged("SelectedEventLevel");
        }
    }

我假设MainPageViewModel继承SimpleViewModelBase

于 2013-03-28T07:35:24.953 回答