Problems with Syncfusion GridTreeControl and Binding

本文关键字:and Binding GridTreeControl Syncfusion with Problems | 更新日期: 2023-09-27 18:37:11

我是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;
    }

我的视图模型 (_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 输出。有人看出这里有什么不对劲吗?

Problems with Syncfusion GridTreeControl and Binding

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

链接:

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

Elavarasan M – 同步软件。