0

这个问题有什么简单的解决方案吗?首先我想我可以创建一个空的 ObservableCollection 并写:

ObservableCollection<PersonDetailsView> newOCollection= new ObservableCollection<PersonDetailsView>();
myDataGrid.ItemsSource=newOCollection.ToArray();

{Binding Person}它有效..我得到一个空行..但问题是我失去了另一个绑定..只有当我的(参见代码)不返回值时,有没有办法绑定到 newOCollection

<DataGrid CanUserAddRows="True" IsReadOnly="False" BorderBrush="#FFCCCCCC"  
        GridLinesVisibility="All" AutoGenerateColumns="False" 
        ItemsSource="{Binding Person}" Background="White" Margin="10,45,0,0" 
        VerticalAlignment="Top" Height="91" HorizontalAlignment="Left" 
        HeadersVisibility="None" SelectionMode="Single" Name="dtaPersons" Width="415">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Person.Name, Mode=TwoWay}" Width="Auto"/>
        <DataGridTextColumn Binding="{Binding Person.Surname, Mode=TwoWay}" Width="*"/>
        <DataGridTemplateColumn Width="Auto">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate >
                    <Button  Style="{DynamicResource ChromelessButtonStyle}" Content="r" FontFamily="Marlett" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
   </DataGrid.Columns>
</DataGrid>
4

1 回答 1

0
ObservableCollection<PersonDetailsView> newOCollection= new ObservableCollection<PersonDetailsView>();

if (!myDataGrid.Items.Any())
    myDataGrid.ItemsSource=newOCollection.ToArray();
于 2013-01-28T16:13:29.327 回答