1

I have a simple DataGrid which I am binding to a ObservableCollection and its producing black small lines in the Grid with no Data Visible. I am using ObservableCollection as I have the collection being built in RunTime using Reflection.

I am doing something like this XAML

   <DataGrid ItemsSource="{Binding Data}" />

C#

public ObservableCollection<object> Data
{ 
        get { return _Data; }
        set { 
            this._deals = value;
            this.NotifyPropertyChanged("Deals");
            }
 }
 public Run()
 {
        this.Data = CreateData(typeof(MyRecordClass))   //'MyRecordClass' needs to be passed at runtime
  }


public ObservableCollection<Object> CreateData(Type RecordType)
{
   ObservableCollection<Object> data = new ObservableCollection<object>();  
   var record = Activator.CreateInstance(RecordType);
    // Logic to load the record with Data 
   data.Add(record);
   return data;
}

Is there a way in which I can make the DataGrid read an ObservableCollection without specifying the ColumnNames or create a ObservableCollection object in the CreateData function ?


Open specific page of a pdf in iFrame on iPad

I am trying to open a specific page of a pdf (for example, http://cb.vu/unixtoolbox.pdf#page=14) inside an iFrame. While it works on desktop browsers, it is not working on an iPad.

Also noticing that, this does not work on the iPad even without the iFrame if I want to go the page 14 by typing http://cb.vu/unixtoolbox.pdf#page=14 directly in the address bar of mobile safari.

Has any of you came across this problem? If so, how did you solve it?

Thanks a lot for any help!

4

1 に答える 1

1

コレクションには public properties が必要なので、データグリッドは列をコレクションにバインドできます。Object のコレクション タイプを使用すると、バインディング用のプロパティがないため、空の行が表示されます。

ここにあなたのための例があります:

public partial class MainWindow : Window { public ObservableCollection dataSource;

    public MainWindow()
    {
        InitializeComponent();

        this.dataSource = new ObservableCollection<SomeDataSource>();

        this.dataSource.Add(new SomeDataSource { Field = "123" });
        this.dataSource.Add(new SomeDataSource { Field = "1234" });
        this.dataSource.Add(new SomeDataSource { Field = "12345" });

        this.dataGrid1.ItemsSource = this.dataSource;
    }
}

public class SomeDataSource
{
    public string Field {get;set;}
}



 <DataGrid AutoGenerateColumns="False" Height="253" HorizontalAlignment="Left" Margin="27,24,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="448">
            <DataGrid.Columns>
                <DataGridTextColumn Header="First" Binding="{Binding Path=Field, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </DataGrid.Columns>
 </DataGrid>
于 2012-09-04T20:58:17.077 に答える