小编Bar*_*Lib的帖子

如何在堆栈面板中滚动数据网格?

我想在datagrid长度超过 时滚动stackpanel,所以我尝试了这个:

<StackPanel Orientation="Horizontal">                         
   <ScrollViewer VerticalScrollBarVisibility="Auto" CanContentScroll="True">
       <DataGrid Name="dgConfig" VerticalAlignment="Stretch" AutoGenerateColumns="False">
             <DataGrid.Columns>
              ...
             </DataGrid.Columns>
       </DataGrid>
   </ScrollViewer>                                
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

但这不起作用,我在此网络上搜索并未能找到任何可用的解决方案。那么我应该如何解决这个问题?谢谢!

c# wpf datagrid scroll stackpanel

4
推荐指数
2
解决办法
2756
查看次数

WPF:调用线程无法访问此对象,因为另一个线程拥有它

我知道有类似的问题,比如Here And Here,我看了他们一切,但他们似乎不适合我.

我有一个帖子:

private void Sample()
{
      Thread t = new Thread(new ThreadStart(Sample_Thread));
      t.SetApartmentState(ApartmentState.STA);
      t.Start();
}
Run Code Online (Sandbox Code Playgroud)

在Sample_Thread中,我之前调用过MessageBox哪个工作正常.

private void Sample_Thread()
{
     try{ ... }
     catch(Exception e)
     {
          MessageBox.Show("SampleText");
     }
}
Run Code Online (Sandbox Code Playgroud)

现在我尝试调用ModernDialog而不是MessageBox,它给了我错误,'The calling thread cannot access this object because a different thread owns it.' 所以我将我的代码更改为:

private void Sample_Thread()
{
     try{ ... }
     catch(Exception e)
     {
            Dispatcher.CurrentDispatcher.Invoke(() =>
            {
                ModernDialog.ShowMessage("SampleText");
            });
     }
}
Run Code Online (Sandbox Code Playgroud)

但是这仍然有同样的错误,我应该如何解决这个问题呢?谢谢!

c# wpf multithreading

0
推荐指数
1
解决办法
5839
查看次数

标签 统计

c# ×2

wpf ×2

datagrid ×1

multithreading ×1

scroll ×1

stackpanel ×1