0

我正在尝试将数据对象绑定到 XamGrid。但是,网格出现空白。这在 Silverlight 4 中有效,但在 Silverlight 5 中不再有效。检查代码显示,在初始化后,绑定到网格的数据对象是空白的,尽管它与数据一起输入。

这是相关的 .xaml

<custCtrls:TcGroupBox Header="Users" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.Row="0">
        <ContentControl>
            <ig:XamGrid x:Name="igUsersGrid" AutoGenerateColumns="False" ColumnWidth="Auto" Height="159" ItemsSource="{Binding Users.Rows, Mode=TwoWay}"  SelectedRowsCollectionChanged="igUsersGrid_SelectedRowsCollectionChanged" Loaded="igUsersGrid_Loaded">
                <ig:XamGrid.RowSelectorSettings>
                    <ig:RowSelectorSettings EnableRowNumbering="False" Visibility="Visible" />
                </ig:XamGrid.RowSelectorSettings>
                <ig:XamGrid.SelectionSettings>
                    <ig:SelectionSettings RowSelection="Single" ColumnSelection="None" CellSelection="None" CellClickAction="SelectRow"/>
                </ig:XamGrid.SelectionSettings>
                <ig:XamGrid.Columns>
                    <ig:TextColumn Key="UserName" HeaderText="UserName" Width="165" MinimumWidth="{StaticResource DefaultMinimumColWidth}" />
                    <ig:TextColumn Key="FirstName" HeaderText="FirstName" Width="165" MinimumWidth="{StaticResource DefaultMinimumColWidth}" />
                    <ig:TextColumn Key="LastName" HeaderText="LastName" Width="165" MinimumWidth="{StaticResource DefaultMinimumColWidth}" />
                    <ig:TemplateColumn Key="Phone" HeaderText="Phone" Width="115" IsReadOnly="True" MinimumWidth="{StaticResource DefaultMinimumColWidth}" >
                        <ig:TemplateColumn.ItemTemplate>
                            <DataTemplate>
                                <ig:XamMaskedEditor Value="{Binding Phone, Mode=TwoWay}" Mask = "(###)###-####" ValidationMode="LostFocus" IsReadOnly="True" Template="{StaticResource XamMaskedEditorControlTemplate1}"/>
                            </DataTemplate>
                        </ig:TemplateColumn.ItemTemplate>
                    </ig:TemplateColumn>
                    <ig:TextColumn Key="Email" HeaderText="Email" Width="160" MinimumWidth="{StaticResource DefaultMinimumColWidth}" />
                    <ig:TextColumn Key="RoleName"  HeaderText="RoleName" Width="160" MinimumWidth="{StaticResource DefaultMinimumColWidth}" />
                    <ig:TextColumn Key="UserId" Visibility="Collapsed" />
                    <ig:TextColumn Key="RoleId" Visibility="Collapsed" />
                </ig:XamGrid.Columns>
            </ig:XamGrid>                       
        </ContentControl>
    </custCtrls:TcGroupBox>

在哪里

xmlns:ig="http://schemas.infragistics.com/xaml" 

这是相关的 .cs 代码

public bool InitializeView(Object viewData)
    {
        _bInitializingControls = true;
        UserControlData data = viewData as UserControlData;

        _dsoUserMgmt = data.ControlData as dsoUserMgmt;
        LayoutRoot.DataContext = _dsoUserMgmt;

        ShowDefaultForm();
        InitializeMenuBar();

        //Initialize menu and toolbar and show default form
        GetUserRoleNames();

        _dsoUserMgmt.Modified = false;

        if (_SelectedUserId > 0)
            SelectUserGridRow(_SelectedUserId);
        _bInitializingControls = false;
        return true;
    }

这是 doUserMgmt.cs 对象的片段

public class dsoUserMgmt : dsoBaseDataSet
{
    protected dtoUsers _Users = new dtoUsers();

    [DataMember]
    public dtoUsers Users
    {
        get { return _Users; }

        set
        {
            Delete(_Users);
            _Users = value;
            Add(_Users);
        }
    }
}

当我在 InitializeView() 中点击以下行时跟踪代码时

LayoutRoot.DataContext = _dsoUserMgmt;

然后它会调用get返回_Users,但它调用了3次。前两个包含数据,第三个调用返回 null。在那之后,DataContect 和网格都是空的。

关于发生了什么的任何想法?这适用于以相同方式设置的另一个网格,并且这用于在 Silverlight 4 中工作。我找到了以下链接,但它们没有帮助(尽管它们阐明了未来可能出现的问题)

Silverlight 5 中的绑定错误?

Silverlight 数据绑定

4

0 回答 0