How to Remove Extra Space Around TextBlock

霸气de小男生 提交于 2019-12-11 04:13:19

问题


I have the following set up for my TextBlock

<TextBox x:Name="SearchTextBlock" InputScope="Search" Opacity="0.999" 
             Height="Auto" VerticalAlignment="Top"
                 BorderBrush="{StaticResource ThemeBrush}" BorderThickness="8" />

which yields

But extra space remains around the TextBlock. How might I remove this? Do I need to create a style or can this be done within the TextBlock tag itself?


回答1:


From the Designer right click on the TextBox and select Edit Template -> Edit a Copy

Choose where do you want to save it and choose it's Key

And then analyzing the code generated you see Margin="{StaticResource PhoneTouchTargetOverhang}" witch you can play with until you like the result.




回答2:


TextBox has a theme style applied to it. Things like margin and padding should be fairly consistent between themes. The best way I've found to "override" the style of something (including a TextBox) is the copy the style resource and tweak it. This is easily done with the Document Outline window.

First, make sure the Document Outline window is visible. This can be done with Ctrl+W,U if you use the Visual C# keyboard thread. Or, View\Other Windows\Document Outline.

Next, make sure the control you want to copy the resource from is selected in the Design surface. Then, go to the document outline and you will see the control selected in there. Right-click the control and select Edit Template/Edit a Copy.... This will create a copy of the style resource (defaulting to within you page XAML. but you have the option of other destinations.). You can then edit that private resource to your heart's content.

In terms of the amount of space around the TextBox, look for things like "MainBorder" in that style.

Update:

verdesrobert's method of getting a copy of the style is much quicker than mine :). Learn something new every day!



来源:https://stackoverflow.com/questions/23048970/how-to-remove-extra-space-around-textblock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!