问题
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