Syncfusion GridTreeControl和绑定的问题

时间:2015-01-11 18:19:58

标签: c# wpf xaml syncfusion

我是WPF的新手,正在使用Syncfusion Framework。我想使用DataTreeControl来显示将在重新安置间隔中加载和更新的数据层次结构。但由于某种原因,它不会显示数据。

这是从我的MainWindow.xaml剪下来的

<syncfusion:TabItemExt Name="_tabItemTipps" Header="Tipps">                  
                    <syncfusion:GridTreeControl Name="_treeGrid"
                                        BorderBrush="LightGray"
                                        BorderThickness="0,0.5,0,0"
                                        EnableHotRowMarker="False"
                                        EnableNodeSelection="True"                                                   
                                        ExpandStateAtStartUp="AllNodesExpanded"
                                        ReadOnly="True"
                                        SupportNodeImages="True"
                                        VisualStyle="Metro"
                                        ItemsSource="SoccerMarkets"
                                       >

                        <!--  Code for GridTreeControl Columns  -->
                        <syncfusion:GridTreeControl.Columns>
                            <syncfusion:GridTreeColumn  HeaderText="Nation" MappingName="{Binding RoughCat}"></syncfusion:GridTreeColumn>

                        </syncfusion:GridTreeControl.Columns>
                    </syncfusion:GridTreeControl>

这是MainWindow.xaml.cs中设置了DataContext的片段:

public MainWindow()
    {
        DataContext = this;
        InitializeComponent();
        SkinStorage.SetVisualStyle(_tabControl, "Metro");
        _settingsVM = new AppSettingsVM();


        _txtBetdaqUser.DataContext = _settingsVM;
        _chkSystemActive.DataContext = _settingsVM;
        _chkInSimulationMode.DataContext = _settingsVM;

        _mechanic = new TippMechanic(_settingsVM);
        _soccerMarketsVM = new SoccerMarketVM();

        Task[] tasks = new Task[1];
        tasks[0] = Task.Factory.StartNew(async () => await _mechanic.Init());//   _mechanic.Init();
        Task.WaitAll(tasks);
        _soccerMarketsVM.SoccerMarkets = _mechanic.SoccerMarketManager.SoccerMarkets;
        _treeGrid.DataContext = _soccerMarketsVM.SoccerMarkets;
    }

我的ViewModel(_soccerMarketsVM)以这种方式定义:

class SoccerMarketVM : ObservableObject
{
    private ObservableCollection<SoccerMarket> _soccerMarkets;

    public ObservableCollection<SoccerMarket> SoccerMarkets
    {
        get { return _soccerMarkets; }
        set
        {
            if(_soccerMarkets != null)
                _soccerMarkets.CollectionChanged -= _soccerMarkets_CollectionChanged;
            _soccerMarkets = value;

            _soccerMarkets.CollectionChanged += _soccerMarkets_CollectionChanged;

        }
    }

    public SoccerMarketVM()
    {
        //_soccerMarkets = new ObservableCollection<SoccerMarket>();
        //_soccerMarkets.CollectionChanged += _soccerMarkets_CollectionChanged;
    }

    void _soccerMarkets_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        Console.WriteLine(e.Action.ToString());
    }
}

CollectionChanged的事件被触发,我得到Console.Writeline输出。 有人看到这里有什么不对吗?

1 个答案:

答案 0 :(得分:2)

在GridTreeControl中,您可以使用不同的方式填充数据。在您的代码段中,ItemsSource定义时未指定Binding关键字,而MappingName是使用Binding关键字定义的。但是对于itemssource,您需要指定绑定和映射名称,您可以直接指定属性名称而无需指定绑定。请参考GridTreeControl中的数据填充的以下UG链接,

链接:

http://help.syncfusion.com/ug/wpf/index.html#!Documents/addingthegridtreecontroltoawpfapplication.htm

Elavarasan M - Syncfusion软件。