Silverlight 5清除使用C#与XamGrid绑定时的数据对象

时间:2012-08-23 18:09:28

标签: c# visual-studio-2010 data-binding infragistics silverlight-5.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,但它会调用它三次。前两个包含数据,第三个调用返回null。在那之后,DataContect以及网格都是空的。

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

Binding bug in Silverlight 5?

Silverlight Data Binding

0 个答案:

没有答案