我想在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)
但这不起作用,我在此网络上搜索并未能找到任何可用的解决方案。那么我应该如何解决这个问题?谢谢!
我知道有类似的问题,比如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)
但是这仍然有同样的错误,我应该如何解决这个问题呢?谢谢!