Silverlight: how to you override part of a theme's style - silverlight

I am using themes from the Silverlight toolkit, however several of them have poor readonly textbox styles (i.e. there is no visual representation when the textbox's are readonly.
How can I use the themes, but tweak a textbox readonly style?
(Because I am extensivly using the dataform this can only apply when the textbox is readony)

Easy enough in Silverlight 4 (once I got a little more familer with styling.
<df:DataForm.ReadOnlyTemplate>
<DataTemplate>
<StackPanel Name="rootPanel"
Orientation="Vertical">
<StackPanel.Resources>
<Style TargetType="TextBox">
<Setter Property="Foreground" Value="LightGray" ></Setter>
<Setter Property="Background" Value="Red" ></Setter>
</Style>

You'd need to start with the XAML and use it (implicit style support is built into Silverlight 4 now), or otherwise rebuild starting with the Toolkit theme you like.

Related

WPF MahApps.Metro AnimatedSingleRowTabControl FontSize

How do I change the font size of the tabs when using the MahApps.Metro AnimatedSingleRowTabControl.
When using a normal TabControl, my theme TabItem (based on MetroTabItem) overrides the fontsize but this does not work for the animated single row tab control. I tried setting the fontsize property on the control in the XAML and this didn't work either.
Regards
Alan
You can also define the following in the Application.Resources your App.xaml:
<system:Double x:Key="TabItemFontSize">16</system:Double>
Controls.TabControl.xaml makes use of it as follows:
<Setter Property="Controls:ControlsHelper.HeaderFontSize"
Value="{DynamicResource TabItemFontSize}" />
You can do the following, setting the header font size to whatever value you want:
<metro:MetroAnimatedSingleRowTabControl>
<metro:MetroAnimatedSingleRowTabControl.ItemContainerStyle>
<Style TargetType="{x:Type metro:MetroTabItem}" BasedOn="{StaticResource {x:Type metro:MetroTabItem}}">
<Setter Property="HeaderFontSize" Value="24"/>
</Style>
</metro:MetroAnimatedSingleRowTabControl.ItemContainerStyle>
</metro:MetroAnimatedSingleRowTabControl>

How to apply WPF styles based on top of another style without using BasedOn property

I am styling CellValuePresenter (From Infragistics) to give different look to Gid Lines and have defined a style (gridLineStyle) and applied to the Grid's CellValuePresenterStyle Property.
I have discovered that there are columns for which custom templates are defined by templating CellValuePrenter and the grid lines are not visible (as expected). I can make it work by applying BasedOn property as in
<Style x:Key="gridLineStyle" TargetType="ig:CellValuePresenter">
<Setter Property="BorderThickness" Value="0,0,1,1"/>
<Setter Property="BorderBrush" Value="{Binding Path=BorderBrushForAllCells,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type pwc:CarbonBlotter}}}"/>
</Style>
<Style x:Key="anotherColumnStyle" TargetType="{x:Type ig:CellValuePresenter}" BasedOn="{StaticResource gridLineStyle}">
<Setter Property="Template">
....
<pwc:BaseXamDataGrid>
<pwc:BaseXamDataGrid.FieldSettings>
<ig:FieldSettings CellValuePresenterStyle="{StaticResource gridLineStyle}"
...
But there are many styles with custom templates, and just wondering whether I can define a style without using BasedOn property and yet inheriting default style
You can find the complete CellValuePresenter style definition in your infragistics installation folder under DefaultStyles\DataPresenter\DataPresenterGeneric_Express.xaml
You can copy that style into your App.xaml under Application.Resources, modify it as you wish and that should become your new default style for CellValuePresenter.

Setting default button style in Windows Phone 7 silverlight app

In WPF I could apply a style to a target type without giving it a name. This would effectively style all elements of that type without explicitly setting the style on each button.
<Style TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="White" />
</Style>
<Button Content="Button1"></Button>
This seems to be giving me problems within WP7 SL as the style is not applied unless I give it an x:Name and set the style on each instance.
<Style x:Key="btnStyle" TargetType="Button">
<Setter Property="BorderBrush" Value="Red" />
</Style>
Is this a chore that I will have to suffer or is there a workaround?
As far as I know, what you have observed in WP7 XAML is inherited from Silverlight. WP7 Silverlight is based on Silverlight 3 and some bits of Silverlight 4.Styles need to be explicitly applied, although this may seem to be too verbose, I personally find defining styles and using them to be best for maintenance of the code.
HTH, indyfromoz

How to change WPF Listbox/ListBoxItem DataTemplate for selected item WITHOUT affecting style & theming?

This question is very similar to Change WPF DataTemplate..., which I have read and implemented. It worked beautifully at first, but I ran into a problem with it.
That problem is that, when using themes in your application such as those in the WPF Futures project (e.g. Expression Dark), the ListBoxItems all revert back to the default WPF styling. This breaks the theme for those elements and, for example, produces black text on black background where the text would otherwise be white. This also affected my TreeView, and presumably would affect other similar controls.
I think this is because conflicting styles are being set for ListBox.ItemContainerStyle--one from the theme and one for switching data templates.
I've looked around for other solutions, but haven't found anything yet. Here are the leads or ideas I've had so far:
Subclassing DataTemplateSelector and setting it to ListBox.ItemTemplateSelector. (The current best bet).
Somehow, somewhere use a Trigger, DataTrigger, or EventTrigger.
Give up on themes.
Somehow hack the functionality I want into the theme.
Somehow make my custom ItemContainerStyle somehow inherit it's colors and eye candy from the theme's style. (I tried it briefly, and it didn't work.)
Here is my ListBox and related pieces:
<Window.Resources>
<DataTemplate x:Key="NormalTemplate">
...
</DataTemplate>
<DataTemplate x:Key="SelectedTemplate">
...
</DataTemplate>
</Window.Resources>
<ListBox x:Name="RegisterListBox" Grid.Row="0"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Adjustments}">
<!-- this is from the post referenced above -->
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="ContentTemplate" Value="{StaticResource NormalTemplate}"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource SelectedTemplate}"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
The Listbox.DataContext is set in code to enable the ItemsSource binding.
Any ideas how I can achieve the kind of functionality described above while maintaining seamless support for themes?
Have you tried doing something like this?
<ListBox.ItemContainerStyle>
<Style
TargetType="{x:Type ListBoxItem}"
BasedOn="{StaticResource {x:Type ListBoxItem}}"> <=====
...
The idea is that the framework will first go look for a style with a key equal to typeof(ListBoxItem), it will find it in the themes, and then your style will just extend the themed one with your specific details.

WPF Trigger for IsSelected in a DataTemplate for ListBox items with Blend

I wanted to change the Foreground color when I selected a listboxItem and I did it using this bit of code:
<DataTrigger Binding="{Binding
RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
<Setter TargetName="descriptionTB" Property="Foreground" Value="#000"/>
</DataTrigger>
You can find the answer here.
But if I want a designer to do this in Blend, how would he do it without drilling into xaml?
Thank you
Artur,
The Triggers designer in Expression Blend only allows adding and modifying EventTriggers and Property triggers. I haven't found a way to add DataTriggers with Blend. I'm also not sure how to set RelativeSource Binding using Blend either. I've always handed code the XAML for test and use Blend for everything else.
Maybe I'm misunderstanding the question but can't you just create a style resource for descriptionTB and let the designer only deal with that style definition and not the binding?
<DataTrigger Binding="..">
<Setter TargetName="descriptionTB" Property="Style" Value="{StaticResource DescriptionTextBoxStyle}" />
</DataTrigger>
In the resources section of your control or window you add the style definition:
<Style TargetType="{x:Type TextBox}" x:Key="DescriptionTextBoxStyle">
<Setter Property="Foreground" Value="#000" />
</Style>
If you want to further isolate the designer from the mechanics of the UI you can create a resource dictionary in a separate xaml file in which you can collect all styles meant for the designer. Then you can merge that resource dictionary with your control's or application's main resources.

Resources