簡體   English   中英

xceed Datagrid模板的DataGrid模板示例

[英]DataGrid Template example with xceed Datagrid Template

我是xceed datagrid的新手,我嘗試為我的普通datagrid克隆代碼,但是它不適用於xceed datagrid。
這是我的示例:

<DataGrid Itemsource="{Binding Path=list}" AutoGenerateColumns="False">
  <DataGrid.Columns>
    <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"/>
  </DataGrid.Columns>
</DataGrid>

那么,這如何與xceed datagrid一起使用?
問候

對於Xceed DataGridControl,ItemsSource是一個DataGridCollectionView。

這是一個簡單的示例:

<Window.Resources>
    <xcdg:DataGridCollectionViewSource x:Key="mySource" Source="{Binding Path=list}" />
</Window.Resources>

<Grid>
    <xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource mySource}}" AutoCreateColumns="False">
        <xcdg:DataGridControl.Columns>
            <xcdg:Column FieldName="FirstName" Title="First Name" />
            <xcdg:Column FieldName="LastName" Title="Last Name" />
        </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
</Grid>

首先添加名稱空間

xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"

要使用DatagridControl,您應該嘗試這樣-

 <xcdg:DataGridControl ItemsSource="{Binding PersonList}" 
                          Margin="0,0,0,100"
                          ReadOnly="{Binding IsGridReadOnly}"
                          >

        <xcdg:DataGridControl.Columns >

            <xcdg:UnboundColumn FieldName="Id"  Visible="False"  />          

            <xcdg:Column FieldName="FirstName"
                            Width="*"
                            Visible="True"   />

            <xcdg:Column FieldName="LastName" 
                         Width="*"
                         Visible="True" />


        </xcdg:DataGridControl.Columns>

    </xcdg:DataGridControl>

在ViewModel中,我有

 private ObservableCollection<Person>  _PersonList ;

    public ObservableCollection<Person> PersonList
    {
        get { return _PersonList; }
        set { _PersonList = value; }
    }

在構造函數中,我正在調用LoadData方法來填充人員列表。 在Person類中,我有3個字段-ID,FirstName和LastName。

在datagrid中,您可以看到有2種類型的列-columnunboundcolumn

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM