I have the following listbox:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,10,0,10">
<TextBlock
Foreground="Black"
Text="{Binding name}"/>
<TextBlock
Foreground="Black"
Text=": "
Visibility="{Binding
Path=name,
Converter={StaticResource ServiceOtherConverter}}"/>
<TextBlock
Foreground="Black"
Text="{Binding amount}"
Visibility="{Binding
Path=name,
Converter={StaticResource ServiceOtherConverter}}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And my app has a white background, so I'd like to set the list items foreground to black. But when I select an item, its foreground doesn't change, as it does whith the default foreground.
How can I change the list items foreground to black but still have the selected foreground different?
You just need to change the Foreground in the Selected VisualState at the style template level for the ListBox Item. For reference you might peek at the msdn doc for ListBox Styles and Templates. Expression Blend makes it pretty painless. Just right-click your item and choose "Edit Additional Templates" and choose the Item template. Then from the States tab, choose the Selected State and change the foreground color. Or you could just do it directly in the template code. Hope this helps.
Related
I am working on Windows Phone 8.1 app. This is my actual requirement.
I want to have my TextBox transparent in editing mode, but I am getting the white color text.
How to get the transparent TextBox? This is my current code:
<Textbox HorizontalAlignment="Left" Margin="175,267,0,0"
TextWrapping="Wrap" PlaceholderText="search contacts"
VerticalAlignment="Top"
Foreground="Black"/>
Simply set the property Background to Transparent. Note that doing this might make it unclear for the user that they're editing the TextBox as both read and edit mode will now look the same.
<Textbox HorizontalAlignment="Left" Margin="175,267,0,0"
TextWrapping="Wrap" PlaceholderText="search contacts"
VerticalAlignment="Top"
Foreground="Black" Background="Transparent" />
My text is getting cutoff in my Panorama View, I am wondering is there away to wrap the text or make it smaller so it won't get cutoff?
Thanks
Have you tried changing the TitleTemplate?
<phone:Panorama Title="my application">
<phone:Panorama.TitleTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontSize="50" Margin="0,50,0,0"/>
</DataTemplate>
</phone:Panorama.TitleTemplate>
</phone:Panorama>
I'm working on windows phone 8 app, and m stuck here, guys i want to show some text as a superscript either in TextBox or in TextBlock where-ever possible. suggest me how can i obtained it. Thanks
Why don't you use a stackpanel wrapping a couple of textblocks instead? Then adjust the margines on the stuff you want super and subscripted.
<StackPanel Orientation="Vertical">
<TextBlock Text="H2O3" FontSize="40" Margin="0,10"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="H" FontSize="40" />
<TextBlock Text="2" FontSize="40" Margin="0,-20,0,0"/>
<TextBlock Text="O" FontSize="40"/>
<TextBlock Text="3" FontSize="40" Margin="0,10,0,-10"/>
</StackPanel>
</StackPanel>
There's an alternative but it's only available in WP8: Typography.Variants.
I personally prefer this approach as it aligns more with WPF but there are cases where you have to do baseline manipulation or in this instance, margin wrangling. If WPF is any indication, it also requires a font that supports variants which are generally open type/true type only. See Superscript / subscript in hyperlink in WPF for a better explanation.
I've got a page design as follows:
The layout is as follows:
<ScrollViewer Margin="0" HorizontalAlignment="Left" Height="360" VerticalAlignment="Bottom">
<StackPanel x:Name="spQueuedWeapons" HorizontalAlignment="Left" VerticalAlignment="Bottom">
<ItemsControl ItemsSource="{Binding QueuedCombinations}" HorizontalAlignment="Left">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageName}">
<i:Interaction.Behaviors>
<ex:MouseDragElementBehavior ConstrainToParentBounds="False" />
</i:Interaction.Behaviors>
</Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
The problem I'm seeing is that the MouseDragElementBehavior seems to be visually constrained to the bounds of the ScrollViewer.
I want to be able to drag the green boxes to the blue drop target.
The only options I've thought of so far have been to remove the containing ScrollViewer or to simulate the StackPanel layout programmatically.
I'd rather not add manual button based scrolling or programmatic layout if possible.
Does anyone have any ideas?
I have this code in my .xaml file
<ListBox Name="Tracks" Margin="0,0,-12,0" ItemsSource="{Binding AllTracks}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="150">
<TextBlock Text="{Binding Name}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding Artist}" TextWrapping="NoWrap" Margin="12,-3,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
<TextBlock Text="{Binding Album}" TextWrapping="NoWrap" Margin="12,3,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
<TextBlock Text="{Binding Duration}" TextWrapping="NoWrap" Margin="12,6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I put data in my list like that(MediaLibrary library = new MediaLibrary();
Tracks.ItemsSource = library.Songs;).
I can see data on my list but when i select something, the selection doesn't highlighted,
how i can fix it? Thanks...
The phone applies the Accent colour as Foreground to the selected element's VisualTree. But since you're overriding the style for all the elements, it's likely that the colour won't be applied.
Try with a regular TextBlock without any Style, and you'll see.
Here: Windows Phone 7 - Setting style for specific control within selected ListBoxItem I've written a bit in response to a similar problem. Please read at least the original post/problem and my answer to it. It may look overwhelming at first as there's not a small amount of extra XAML, but in fact it is quite easy to follow and once you look at it as a several different aspects (template, styles, visualstates) - it turns out to be .. quite short, paradoxically. Once you read through it, you will probably notice that your problem is almost exactly the same, with the minor difference that the 'animated' property/target from foreground of textbox to a background of the panel..