Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Silverlight桌子太大,一张放不下”;“查看”;该网页的。我怎样才能随着时间的推移把桌子移下来?_C#_Silverlight - Fatal编程技术网

C# Silverlight桌子太大,一张放不下”;“查看”;该网页的。我怎样才能随着时间的推移把桌子移下来?

C# Silverlight桌子太大,一张放不下”;“查看”;该网页的。我怎样才能随着时间的推移把桌子移下来?,c#,silverlight,C#,Silverlight,我正在尝试创建一个以表格格式显示某些信息的程序。此表的行数可能会更改,因此,在一次查看网页时,该表可能完全可见,也可能不完全可见 有没有一种方法可以让我随着时间的推移展示桌子的各个部分?例如:显示第1-30行1分钟,然后显示第31-50行1分钟,然后再返回第1-30行1分钟,依此类推 到目前为止,我掌握的代码是: XAML: 使用系统; 使用System.Collections.Generic; 使用System.Linq; Net系统; 使用System.Windows; 使用Syst

我正在尝试创建一个以表格格式显示某些信息的程序。此表的行数可能会更改,因此,在一次查看网页时,该表可能完全可见,也可能不完全可见

有没有一种方法可以让我随着时间的推移展示桌子的各个部分?例如:显示第1-30行1分钟,然后显示第31-50行1分钟,然后再返回第1-30行1分钟,依此类推

到目前为止,我掌握的代码是:

XAML:


使用系统;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Animation;
使用System.Windows.Shapes;
使用系统诊断;
名称空间MyNameSpace
{
公共部分类主页面:UserControl
{
//numRows的值将取决于数据库中的值,因此它可能每隔一段时间更改一次。
int numRows=45;
边框=新边框();
边界边界2=新边界();
公共主页()
{
初始化组件();
createRows();
}
公共边框初始设置顺序(边框b)
{
b、 BorderBrush=新的SolidColorBrush(颜色为黑色);
b、 边界厚度=新厚度(1);
返回b;
}
public void createRows()
{
//此for循环创建必要数量的行。
对于(int i=0;i

}

以下是从服务创建datagrid的简单示例

重复此过程:

从服务获取数据 解析数据 将其指定为数据网格的源项


使用Dispatcher Timer,在每分钟或任何时间间隔后从服务中获取xml数据,对其进行解析并将其分配给Datagrid。

以下是一些如何经常显示不同“页面”数据的方法。这种方法使用DataGrid而不是ItemsControl,因为DataGrid不需要您指定ItemTemplate。我还没有测试过这段代码,但希望它能让你走上正轨

快速提问:有什么理由不能一次将数据全部扔进UI,让用户上下滚动?然后,您可以完全禁用Dispatcher和寻呼

在XAML中,添加
xmlns:c=“clr命名空间:System.Windows.Controls;assembly=System.Windows.Controls.Data”
并用以下内容替换InnerGrid:

<c:DataGrid x:Name="MyDataGrid" Grid.Row="1" AutoGenerateColumns="True" />

在代码隐藏中:

private IEnumerable<MyDataObject>[] _pages;
private int _currentPageIndex = 0;
private ObservableCollection<MyDataObject> _visibleData;
private DispatcherTimer _timer;

public MainPage()
{
    InitializeComponent();

    this._visibleData = new ObservableCollection<MyDataObject>();
    this.MyDataGrid.ItemsSource = this._visibleData;

    this._timer = new DispatcherTimer();
    this._timer.Interval = TimeSpan.FromMinutes(1);
    this._timer.Tick += (sender, args) => this.OnTimerTick();
    this._timer.Start();
}

// I assume you have some code that gets data from the server. Pass that data to this method.
private void ProcessDataFromServer(IEnumerable<MyDataObject> data)
{
    this._pages = this.GroupDataIntoPages(data);
    this.ShowPage(0);
}

private IEnumerable<MyDataObject>[] GroupDataIntoPages(IEnumerable<MyDataObject> data)
{
    // I'll leave this to you.
    // This might help: http://stackoverflow.com/a/860399/674077
}

private void OnTimerTick()
{
    if(this._pages != null)
    {
        this._currentPageIndex++;
        if(this._currentPageIndex >= this._pages.Length)
        {
            this._currentPageIndex = 0;
        }
        this.ShowPage(this._currentPageIndex);
    }
}

private void ShowPage(int pageIndex)
{
    this._visibleData.Clear();
    if(this._pages != null && pageIndex >= 0 && pageIndex < this._pages.Length)
    {
        foreach(var item in this._pages[pageIndex])
        {
            this._visibleData.Add(item);
        }
    }
}
private IEnumerable[]\u页面;
private int_currentPageIndex=0;
私有可观察收集(可视数据);;
私人调度员定时器;
公共主页()
{
初始化组件();
这._visibleData=新的ObservableCollection();
this.MyDataGrid.ItemsSource=此。\ u visibleData;
这是。_timer=newdispatchermer();
此._timer.Interval=TimeSpan.FromMinutes(1);
this._timer.Tick+=(发送方,参数)=>this.OnTimerTick();
这是。_timer.Start();
}
//我假设您有一些从服务器获取数据的代码。将该数据传递到此方法。
私有void ProcessDataFromServer(IEnumerable数据)
{
this.\u pages=this.GroupDataIntoPages(数据);
此.ShowPage(0);
}
私有IEnumerable[]GroupDataIntoPages(IEnumerable数据)
{
//我把这个留给你。
//这可能有助于:http://stackoverflow.com/a/860399/674077
}
私有void OnTimerTick()
{
如果(此._页!=null)
{
这个;
如果(this.\u currentPageIndex>=this.\u pages.Length)
{
这是.\u currentPageIndex=0;
}
this.ShowPage(this.\u currentPageIndex);
}
}
专用void显示页(int pageIndex)
{
这是._visibleData.Clear();
如果(this.\u pages!=null&&pageIndex>=0&&pageIndex
您是否考虑过使用or而不是在代码隐藏中构建网格?然后可以绑定到使用定期刷新的。如果你愿意,我可以提供更多的细节。嘿,安德鲁,是的,如果你能提供更多细节,那就太棒了。。我是silverlight的noob所以这会很有帮助
<c:DataGrid x:Name="MyDataGrid" Grid.Row="1" AutoGenerateColumns="True" />
private IEnumerable<MyDataObject>[] _pages;
private int _currentPageIndex = 0;
private ObservableCollection<MyDataObject> _visibleData;
private DispatcherTimer _timer;

public MainPage()
{
    InitializeComponent();

    this._visibleData = new ObservableCollection<MyDataObject>();
    this.MyDataGrid.ItemsSource = this._visibleData;

    this._timer = new DispatcherTimer();
    this._timer.Interval = TimeSpan.FromMinutes(1);
    this._timer.Tick += (sender, args) => this.OnTimerTick();
    this._timer.Start();
}

// I assume you have some code that gets data from the server. Pass that data to this method.
private void ProcessDataFromServer(IEnumerable<MyDataObject> data)
{
    this._pages = this.GroupDataIntoPages(data);
    this.ShowPage(0);
}

private IEnumerable<MyDataObject>[] GroupDataIntoPages(IEnumerable<MyDataObject> data)
{
    // I'll leave this to you.
    // This might help: http://stackoverflow.com/a/860399/674077
}

private void OnTimerTick()
{
    if(this._pages != null)
    {
        this._currentPageIndex++;
        if(this._currentPageIndex >= this._pages.Length)
        {
            this._currentPageIndex = 0;
        }
        this.ShowPage(this._currentPageIndex);
    }
}

private void ShowPage(int pageIndex)
{
    this._visibleData.Clear();
    if(this._pages != null && pageIndex >= 0 && pageIndex < this._pages.Length)
    {
        foreach(var item in this._pages[pageIndex])
        {
            this._visibleData.Add(item);
        }
    }
}