Reputation: 7560
How do I override static resources in Windows Phone 7 Apps?
I am stacking many TextBoxes in a list and I want to make the margin between them smaller, but without retemplating the entire control.
I figured PhoneTouchTargetOverhang is whats causing the large margin. How do I override it?
I have tried adding this to my PhoneApplicationPage.Resources:
<Thickness x:Key="PhoneTouchTargetOverhang">0</Thickness>
... but it is not affecting anything.
Also I'm trying to override other resources such as default background and foreground colors without success. Whatever I do, nothing happens.
Clarification:
Upvotes: 1
Views: 2016
Reputation: 7424
You should check out these resources when trying to change static resources:
How to: Apply Theme Resources for Windows Phone
and also
Resources Overview - This actually shows how to style a textbox in xaml (in your case the textbox control). Since your working in wp7 you can declare these in the app.xaml file. This is a nice approach if you wish to apply these styles throughout the app. If not Praetorian's solution is an alternative for specific controls you would like to style.
From what I've used there is no reason why this shouldn't work. And honestly in my opinion it's better (neater) to create a template than start applying negative margins on individual controls in your xaml files.
Be aware also that there is a reason for the margins for user experience purposes. Put them too close and it makes it difficult to select a certain control. I believe there is a requirement for in the design guidelines but I'm not sure exactly.
Here is an example of what to put in app.xaml:
<Style x:Key="TextBoxStyle1" TargetType="TextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Here is full example on creating a template for the textbox control, if you don't want to start from scratch.
HTH.
Upvotes: 0
Reputation: 109119
I haven't tried this out but setting the Top
and Bottom
margins to negative numbers should move the TextBox
es closer together.
<TextBox Margin="0,-10,0,-10" Text="Some text"/>
Upvotes: 1
Reputation: 66882
I might have misunderstood...
But if you're just repeating the TextBoxes inside a databound ListBox then you I think could just set the Margin for these TextBoxes inside the DataTemplate.
<ListBox ItemsSource="{...}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBox Margin="0" Text="{...}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Upvotes: 0