WPF StackPanel 之间有间距
我的堆栈面板的每个项目(文本块)之间都有间隙。您可以看到背景画布后面的任何内容。我不想要间隙。 我尝试将堆栈面板和文本块的边距设置为零。没有修好。 在 Blend 中创建相同的东西没有显示任何差距(据我所知)。
(来源:synthedit.com)
在这里,您可以看到鼠标/驼鹿后面的物体通过间隙显示出来。
StackPanel^ tstack = gcnew StackPanel;
canvas->Children->Add( tstack );
canvas->SetLeft( tstack, 100 );
canvas->SetTop( tstack, 100 );
canvas->SetZIndex( tstack, 3 );
TextBlock^ tBlock = gcnew TextBlock();
tBlock->FontSize = 10;
tBlock->Text = L"mouse";
tBlock->Background = Brushes::LightGray;
tstack->Children->Add( tBlock );
tBlock = gcnew TextBlock();
tBlock->FontSize = 10;
tBlock->Text = L"moose";
tBlock->Background = Brushes::LightGray;
tstack->Children->Add( tBlock );
My stackpanels have gaps between each item (TextBlocks). You can see through to whatever is behind on the background Canvas. I don't want gaps.
I tried setting the margin of both the stackpanel and textblocks to zero. Didn't fix it.
Creating the same thing in Blend shows no gaps (AFAIK).
(source: synthedit.com)
Here you can see the object behind mouse/moose showing thru the gap.
StackPanel^ tstack = gcnew StackPanel;
canvas->Children->Add( tstack );
canvas->SetLeft( tstack, 100 );
canvas->SetTop( tstack, 100 );
canvas->SetZIndex( tstack, 3 );
TextBlock^ tBlock = gcnew TextBlock();
tBlock->FontSize = 10;
tBlock->Text = L"mouse";
tBlock->Background = Brushes::LightGray;
tstack->Children->Add( tBlock );
tBlock = gcnew TextBlock();
tBlock->FontSize = 10;
tBlock->Text = L"moose";
tBlock->Background = Brushes::LightGray;
tstack->Children->Add( tBlock );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该不需要设置边距。 Kaxaml 中的简单测试证实元素之间不应该有间隙。两个可能的原因是 1) 在应用程序资源中或可视化树中某处设置的隐式样式,或 2) 可视化树中某处 SnapsToDevicePixels=false 或 UseLayoutRounding=true。
There should be no need to set margins. A simple test in Kaxaml confirms that there should be no gap between elements. Two possible causes would be 1) an implicit style that is set in your application resources or somewhere in the visual tree or 2) SnapsToDevicePixels=false or UseLayoutRounding=true somewhere in the visual tree.