Where the styles are taken from? - xaml

I have a question
I've created new win8 metro app and I don't get from where it is taking styles.
I've change in App.xaml name of styles file. My Style.xaml looks like this
<!-- Page layout roots typically use entrance animations and a theme-appropriate background color -->
<Style x:Key="LayoutRootStyle" TargetType="Panel">
<Setter Property="Background" Value="White"/>
<Setter Property="ChildrenTransitions">
<Setter.Value>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Setter.Value>
</Setter>
</Style>
But still I got gold letters, my buttons change white when I'm hover it. Same like with default StandardStyles.xaml
What am I doing wrong ? Or it works just fine ?

The style you show would only affect the the panel that uses that style. If you put a button inside a the panel, the panel's style does not cascade to the button. The button has its own style, as you correctly deduced from standardstyles.xaml, that controls its appearance. If you want to change the style of the button, you need to create a new style or update the current style.

The problem is you gave your style a key using the x:Key attribute. Once a style has a key it will only be applied to controls that implicitly use that named style. If you remove the key, the style should be applied to all controls that match TargetType (in this case Panel).

Related

Styling for ListBox, ListView and GridView Items

The default colors for these controls seems to be similar to the Windows theme colors. How do you change the hover, selected, selected hover and pressed colors (code or XAML)? The following isn't working for the ListView:
<ListView>
<ListViewItemPresenter
PointerOverBackground="#99CEEA"
SelectedPressedBackground="#72BFE9"
SelectedBackground="#72BFE9"
SelectedPointerOverBackground="#99CEEA"
/>
In your VS/Blend Designer, right click on your ListView and select
Edit Additional Templates > Edit Generated Item Container
(ItemContainerStyle) > Edit a Copy...
In the popup window above, if you want this style to be applied to all your ListViewItem, select Apply to all otherwise just give it a name.
I'd recommend to create a new Resource dictionary for storing all ListView related styling. To do so, just hit the New... button and give the resource dictionary a name (e.g. ListViewStyles.xaml).
Finally, hit the OK button and you now have a fully generated style.
In the style's ControlTemplate, you can locate the ListViewItemPresenter control and update its colors accordingly.
The ListViewItemPresenter was in the wrong place in the XAML. Change this:
<ListView>
<ListViewItemPresenter
PointerOverBackground="#99CEEA"
SelectedPressedBackground="#72BFE9"
SelectedBackground="#72BFE9"
SelectedPointerOverBackground="#99CEEA"
/>
</ListView>
to this:
<ListView>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter
PointerOverBackground="#99CEEA"
SelectedPressedBackground="#72BFE9"
SelectedBackground="#72BFE9"
SelectedPointerOverBackground="#99CEEA" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView>

What is the Default Font Foreground for Windows Phone Controls

I am trying to match the default font of the ToggleSwitch Header property from the WPToolkit to a TextBlock. I've noticed that the default font of the ToggleSwitch header does not math the TextBlock. What can I use to apply the some text foreground to a TextBlock?
Have you looked at the existing Style template Setter for that property to see what it's using and just apply the same to the Style template for the other? So if for example we look at the template shared on MSDN for the default Style it shows on line 7;
<Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}" />
So you could either set it to that via the default template for TextBlock in the Resource Dictionary or say for example all your instances within a user control like;
<Blah.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}" />
</Style>
</Blah.Resources>
Hope this helps.
UPDATE NOTE: I apparently grabbed the default template of the windows store app Toggle instead of the Windows phone but the same question applies of checking whats in the default template and matching it to the other.

What gives the hover and click styles in w8 xaml?

When using a listitem in a w8 app, how can I determine what gives the hover and click styles?
My listview looks like this:
<ListView x:Name="itemsListView"
TabIndex="1"
Visibility="Visible"
Padding="10,0,0,0" Foreground="Black"
ItemsSource="{Binding Nodes.Nodes}"
behaviors:ListViewItemClickedToAction.Action="{Binding SelectNodeAction}"
IsItemClickEnabled="True" FontFamily="Global User Interface"
>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
When I hover using the mouse I get white letters and an almost white background.
I have tried reusing parts of the adventureworks shopper app, so there are styles from there copied. However, I can't understand what is applied to the ListView items.
You maybe already new this but if you check this screenshot you can see how you easily in VS2012 can create a copy of a built in style. When you press the "Edit a copy ..." a dialog will appear where you can choose where in the Project you want the style to be placed.
You can inherit styles. The inheritence of styles work in the following way:
<Style x:Name="BasicStyle" TargetType="Button">
<Setter Property="Background" Value="Green" />
</Style>
<Style x:Name="ButtonStyle" TargetType="Button" BasedOn="{StaticResource BasicStyle}">
<Setter Property="Foreground" Value="Red" />
</Style>
You can do inheritence in several steps so Another button style can inherit the "ButtonStyle".
You can thus make a style that only contains the Template property if you want to seperate it or reuse the behaviour and look of your style. But you cannot split the Visual State Manager into several styles since if you inherit a style which sets the template property and then if you want to change the Hover state of that style you need to make a copy of the whole template and only change that part in the code.
I Think this would be a nice improvement by MS if you could make a style which only contains the pressed state and then Another style which only contains the hover effect and so on.
I hope this answers your questions :) I would love to answer more questions regarding XAML if you have any!

Giving a specific style to DataGrid element (implicitly)

I'm trying implicitly apply a style for DataGrid and TextBlocks.
For TextBlock's ForeGround I need White color.
For DataGrid's rows I need Black Color.
Beside this I need White again for DataGrid's header columns.
When I globally apply an implicit style for on MainPage by
<UserControl>
<UserControl.Resorces>
<Style targetType="TextBlock">
<Setter Property="Foreground" Value="White"/>
</Style>
</UserControl.Resorces>
</UserControl>
Making TextBlock's Foreground White operation is done! But beside this all of elements
in DataGrid (By default content elements are textblock's I think) turn to White color.
It doesn't look good White on white as you guess :)
So how can I particularly specify DataGrid's elements Foreground to black?
I can do it by using same technic shown below ,but this is an expensive operation for each DataGrid. As a con more I want DataGrid's HeaderColumns white again.This operation make them all black.
Is there an explicit way such as we do in css styles?
Here is what I tried to achieve this goal by Control template. But no chance because of being DataGrid's ContentControl is dynamic.
<DataGrid>
<DataGrid.Resources>
<Style targetType="TextBlock">
<Setter Property="Foreground" Value="Black"/>
</Style>
<DataGrid.Resources>
In fact we use Telerik's RadGridView but I give a sdk's DataGrid example to make question more global.
<Style TargetType="sdk:DataGrid">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="RowDetailsTemplate" Value="{StaticResource DataTemplate1}"/>
<Setter Property="Template" Value="{StaticResource ControlTemplate1}"/>
</Style>
<ControlTemplate x:Key="ControlTemplate1" TargetType="sdk:DataGrid">
<Grid/>
</ControlTemplate>
<DataTemplate x:Key="DataTemplate1">
<Grid/>
</DataTemplate>
Thanks in advance!
If it were me I would pull out the full control templates and style them accordingly instead of trying to just do adhoc setter changes to override bits of the original template. In Expression Blend right click, choose "Edit Template -> Edit A Copy" and break out the templates for your rows etc and apply those implicitly with StaticResource instead.

Can I apply a style to a XAML element based on what parent element it has?

What is the correct way to apply styles on elements with a condition on their parent element's type, i. e. only if they are children of certain other elements?
In my case, I want to apply some exact button width and height, but only if those buttons are direct children of a stackpanel. Additionally, a second style should be applied to images within those buttons (glyphs).
How do I define a button style that only affects buttons on a stackpanel, but not those buttons placed directly on a grid?
Is it possible to add additional conditions such as only stackpanels with orientation="horizontal"?
Can I define "tree conditions" like only images on buttons on [horizontal] stackpanels?
As 90% of all buttons in my application are those on the stackpanels, so far I've applied the style to all buttons and images and overrode it where necessary. But this isn't the best solution, is it?
Preferably, the solution would deal with all the conditions in the style definition, so I won't have to explicitly assign that style to every single one of my stackpanels.
<StackPanel>
<StackPanel.Resources>
<Style x:Key="Rectangle1" TargetType="Rectangle">
<Setter Property="Stroke" Value="Black" />
<Setter Property="Fill" Value="White" />
</Style>
</StackPanel.Resources>
<UniformGrid Columns="10">
<UniformGrid.Resources>
<Style TargetType="Rectangle" BasedOn="{StaticResource Rectangle1}">
<Setter Property="Fill" Value="Red" />
</Style>
</UniformGrid.Resources>
</UniformGrid>
</StackPanel>