I am using MahApps TabControl and i have several TabItems:
<TabControl Name="tabControl" FontSize="12">
<TabItem Header="Statistics" />
</TabControl>
I try to change the font size of the TabControl and TabItems in order to resize my headers but it seems that this not changing anything.
You should use the attached property HeaderFontSize to set the header font size of the tav items.
<TabControl Name="tabControl">
<TabItem Header="Statistics" Controls:ControlsHelper.HeaderFontSize="12" />
</TabControl>
or
<TabControl Name="tabControl">
<TabControl.Resources>
<Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="12" />
</Style>
</TabControl.Resources>
<TabItem Header="Statistics" />
</TabControl>
Hope that helps.
In 2.* versions of MahApps.Metro it changes to:
<TabControl Name="tabControl">
<TabItem Header="Statistics" Controls:HeaderedControlHelper.HeaderFontSize="12" />
</TabControl>
or
<TabControl Name="tabControl">
<TabControl.Resources>
<Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
<Setter Property="Controls:HeaderedControlHelper.HeaderFontSize" Value="12" />
</Style>
</TabControl.Resources>
<TabItem Header="Statistics" />
</TabControl>
Source: https://github.com/MahApps/MahApps.Metro/issues/3711
Documentation is not available at the time of writing.
Put the below code in Window.Resources
<Window
......
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
......
>
<Window.Resources>
<Style x:Key="MenuLevel2" BasedOn="{StaticResource MetroTabItem}" TargetType="{x:Type TabItem}">
<Setter Property="mah:ControlsHelper.HeaderFontSize" Value="15"></Setter>
</Style>
<Window.Resources>
In the TabItem section add the style details.
<TabItem Header="Dimension Alias" Style="{DynamicResource MenuLevel2}">
This worked for me.
since tabItems is a list of item having some common bindings modifying one of Tabitem header height will automatically do for the others
<TabControl>
<TabItem >
<TabItem.Header>
<Label Height="30" Content="Main" FontSize="16" >
</Label>
</TabItem.Header>
</TabItem>
<TabItem Header="Second header" >
<TabItem Header="Third header" >
</TabControl>
In my case this has solved my problem:
<TabControl>
<TabControl.Resources>
<Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="12" />
</Style>
</TabControl.Resources>
</TabControl>
Since 2.0 we have to use this in your App.xaml or directly in the resources of your control:
<System:Double x:Key="MahApps.Font.Size.TabItem">16.67</System:Double>
Related
After several hours I gave up.
I have the following ListView (in Grid) with GroupStyle defined inside of it.
I want to take it out somehow and put it in a Template or Style (I'm confused) and then add it to my main Style of the ListView (ListViewSimpleStyle).
This way it will be reusable in other places instead of copy-paste it every time.
How do I do it?
<ListView Name="LvDataBinding" Grid.Row="0"
Style="{StaticResource ListViewSimpleStyle}">
<!-- Define the grouping-->
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock FontSize="12" Text="{Binding Name}"
Foreground="{StaticResource GrayForgroundBrush}"></TextBlock>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
Thanks
Groupstyle is style of Groupbox so we need to edit style of Groupbox and I have changed GroupBox HeaderTemplate as you want to change HeaderTemplate of GroupStyle.
Visit this:http://msdn.microsoft.com/en-us/library/ms754027(v=vs.90).aspx
and Add GroupBox With Its style in your own listview template style i.e ListViewSimpleStyle
<Style x:Key="ListViewSimpleStyle" TargetType="ListView">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
<Grid Background="AliceBlue" >
<GroupBox>
<GroupBox.Style>
<Style TargetType="GroupBox">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock FontSize="12" Text="{Binding Name}" Foreground="{StaticResource GrayForgroundBrush}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupBox.Style>
</GroupBox>
<ItemsPresenter></ItemsPresenter>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I have a ComboBox which i want to style with some custom style. I was successful in providing the required style. In the style i have the following elements :
Template for a toggle button
A pop-up which holds items of the ComboBox
Almost all the links i referred to, used the same approach. But with this approach i am not able to provide a template for the items in the ComboBox. For some reason the item template i am defining is not being used for rendering the items. Could someone help me out?
I am pasting a sample of code to make my problem statement clear(There might be mistakes in the code, i just want an idea to proceed).
<Window.Resources>
<Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<ToggleButton Template="{StaticResource MyToggleButton}"/>
<Popup >
<StackPanel>
<Border/>
<ItemsPresenter/>
</StackPanel>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<ComboBox Style="{StaticResource MyStyle}">
<ComboBox.ItemTemplate>
<DataTemplate>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
If you're trying to provide a different ControlTemplate for your ComboBoxItem controls you need to set the ItemContainerStyle property on your ComboBox to a Style similar to what you've already done with the parent control, but for ComboBoxItem. ItemTemplate defines a DataTemplate to apply to the data for each item which is then injected into that ComboBoxItem ControlTemplate.
<ComboBox Style="{StaticResource MyStyle}">
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border>
<ContentPresenter/> <!--ItemTemplate is injected here-->
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ComboBox.ItemContainerStyle>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=SomePropertyOnMyDataObject}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
I'm trying to write a HeaderTemplate for an extender. So far, I've noticed all the examples use the {Binding} keyword to get the data from the header. However, what happens if there are multiple controls within the Header? How do I specify that those controls should be inserted at a specific location?
<Window.Resources>
<Style x:Key="ExpanderStyle" TargetType="{x:Type Expander}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<!-- what do I put in here? -->
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Expander Style="{StaticResource ExpanderStyle}">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock>Some Text</TextBlock>
<TextBlock Text="{Binding SomeBinding}" />
<Button />
</StackPanel>
</Expander.Header>
<Image Source="https://www.google.com/logos/2012/steno12-hp.jpg" />
</Expander>
Should I be moving my binding into the HeaderTemplate in the style and just overwriting whatever the Header in the Expander is?
You can use ContentPresenter to insert whatever the usual content would be into your Template
For example:
<Style x:Key="ExpanderStyle" TargetType="{x:Type Expander}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<Border BorderBrush="Blue" BorderThickness="2">
<ContentPresenter />
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Header's property Content could contain only one object.
If you merge these object in one panel:
<StackPanel>
<TextBlock>Some Text</TextBlock>
<TextBlock Text="{Binding SomeBinding}" />
<Button />
</StackPanel>
then in template you could use {binding}
I have a ListView and i'd like to set up a context menu which i can open not only when right-clicking some text in some column but anywhere on the ListViewItem, to do so i thought i'd just set my ContextMenu using a style setter since i cannot directly access the ListViewItem.
Unfortunately when you try to do it like this it won't compile:
<Style TargetType="ListViewItem">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Header" Click="Handler"/>
...
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
Error 102 'Handler' is not valid.
'Click' is not an event on
'System.Windows.Controls.GridView'.
I figured that you can avoid this by using an EventSetter for the Click-event. But it is apparent that the code gets quite inflated from all the wrapping tags you need.
My question is if there is some workaround so you do not have to deal with EventSetters.
Edit: See this question for an explanation on why this error occurs.
You can put the ContextMenu in the ListView's Resources and then use it as a static resource, that way you won't have to use a Style for the MenuItem's
<ListView ...>
<ListView.Resources>
<ContextMenu x:Key="listViewContextMenu">
<MenuItem Header="Header" Click="MenuItem_Click"/>
</ContextMenu>
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="ContextMenu" Value="{StaticResource listViewContextMenu}"/>
</Style>
</ListView.ItemContainerStyle>
<!--...-->
</ListView>
You can just ListBoxItem.HorizontalContentAlignment to Stretch and then put the ContextMenu in your ListBox.ItemTemplate. Here's an example:
<Grid>
<Grid.Resources>
<PointCollection x:Key="sampleData">
<Point X="10" Y="20"/>
<Point X="30" Y="40"/>
</PointCollection>
</Grid.Resources>
<ListBox Width="100" ItemsSource="{StaticResource sampleData}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="Red">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Test" Click="MenuItem_Click"/>
</ContextMenu>
</Grid.ContextMenu>
<TextBlock Text="{Binding}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
I am trying to create a Tab Control in WPF that has the tabs arranged down the right side of the control, with the text rotated 90 degrees The look is similar to those plastic tabs you can buy and use in a notebook. I have tried changing the TabStripPlacement to Right, but it just stacks the tabs up on the top right side of the control - not at all what I had in mind.
The effect I believe you are seeking is achieved by providing a HeaderTemplate for the TabItem's in you Tab collection.
<TabControl TabStripPlacement="Right">
<TabControl.Resources>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Padding" Value="4" />
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<ContentPresenter Content="{TemplateBinding Content}">
<ContentPresenter.LayoutTransform>
<RotateTransform Angle="90" />
</ContentPresenter.LayoutTransform>
</ContentPresenter>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabItem Header="Tab Item 1" />
<TabItem Header="Tab Item 2" />
<TabItem Header="Tab Item 3" />
<TabItem Header="Tab Item 4" />
</TabControl>
Hope this helps!