I am trying to change the style of the tooltip of DataGridTextColumn, But the xaml code below doesn't work. When I run the application, custom tooltip is shown and System.Windows.Style is written in it. The button isn't shown too. Where do I have mistake?
<DataGrid.Columns>
<DataGridTextColumn Width="*" Binding="{Binding W_NAME}" Header="Name">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ToolTip">
<Setter.Value>
<Style TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="HasDropShadow" Value="True"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Content" Value="mytext"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Border Name="RootElement" CornerRadius="2,2,0,0">
<Border.Background>
<SolidColorBrush x:Name="BorderBrush" Color="Black"/>
</Border.Background>
<Grid Margin="4" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
TextElement.FontFamily="{DynamicResource Glaho}"
Content="{TemplateBinding Content}"
Margin="4,5,4,4">
</ContentPresenter>
<Button Content="This is button" HorizontalAlignment="Right" Command="{Binding somecommand}"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
You're very close, the problem is you've set the Style as the ToolTip itself:
<Style TargetType="DataGridCell">
<Setter Property="ToolTip">
<Setter.Value>
<Style TargetType="ToolTip"> <-------------- badness!
What you need to do is set a ToolTip control as the ToolTip, and then set the Style on that:
<Style TargetType="DataGridCell">
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip>
<ToolTip.Style>
<Style TargetType="ToolTip">
Related
I have code in xaml and trying create controlTemplae
<ListView Name="seznamSkupin" Background="White" Grid.Row="1" Grid.Column="0" BorderBrush="#a9a9a9" BorderThickness="0,0,1,0" Padding="0,30">
<ListView.ItemContainerStyle>
<Style>
...structure...
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource gridViewHeader}">
<GridViewColumn DisplayMemberBinding="{Binding NazevSkupiny }"/>
</GridView>
</ListView.View>
</ListView>
Data are in code behind
List<Skupina> skupina = new List<Skupina>();
string[] skupiny = {"Test", "3.A", "3.B"};
for (int i = 0; i < skupiny.Length; i++)
{
skupina.Add(new Skupina() { NazevSkupiny = skupiny[i]});
}
seznamSkupin.ItemsSource = skupina;
It works in xaml, but I need to create template for listView, - I have two listViews and nedd to use same styles. I am using separate style.xaml, trying this, but content of "seznamSkupin" is not showed:
<Style x:Key="dialogListView" TargetType="{x:Type ListView}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListView}">
<ListView Background="{StaticResource color3}" BorderThickness="0" Padding="0,30">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="FontFamily" Value="{StaticResource fontFamilyDefault}" />
<Setter Property="FontSize" Value="{StaticResource fontSize3}" />
<Setter Property="Foreground" Value="{StaticResource color5 }" />
<Setter Property="Margin" Value="12,0"/>
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border CornerRadius="0" SnapsToDevicePixels="True"
BorderThickness="0,0,0,1"
BorderBrush="Black"
Background="{TemplateBinding Background}"
>
<Border x:Name="InnerBorder" CornerRadius="0" BorderThickness="0,3,0,3" BorderBrush="white" Padding="0,3" >
<Grid>
<GridViewRowPresenter VerticalAlignment="Center" HorizontalAlignment="Left" SnapsToDevicePixels="True" Content="{TemplateBinding Content}" Columns="{TemplateBinding GridView.ColumnCollection}" />
</Grid>
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="{StaticResource color1}" />
<Setter Property="Foreground" Value="{StaticResource color4}" />
<Setter Property="BorderBrush" Value="Transparent" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I think, problem is in GridViewRowPresenter can anybody help? Thanks!
So inside ListView.View i have this Style than i am using in order to remove Header borders:
<GridView ColumnHeaderContainerStyle="{StaticResource ListViewHeaderDefaultStyle}">
</GridView>
Style
<Style x:Key="ListViewHeaderDefaultStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Border BorderThickness="0,0,0,1" BorderBrush="{DynamicResource GridViewColumnHeaderBorderBrushColor}" Background="Transparent">
<TextBlock x:Name="ContentHeader"
Text="{TemplateBinding Content}"
Padding="0,5,0,0"
Width="{TemplateBinding Width}"
TextAlignment="Left"
FontSize="13"
Margin="5,0,0,0"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Foreground" Value="{DynamicResource GridViewColumnHeaderForegroundColor}"/>
<Setter Property="FontFamily" Value="{DynamicResource applicationFontFamily}"/>
<Setter Property="FontSize" Value="{DynamicResource GridViewColumnHeaderFontSize}"/>
</Style>
And inside my Column Header i want to add Combobox:
<GridViewColumn Width="100" CellTemplate="{StaticResource ComboBoxDataTemplate}">
<GridViewColumn.Header>
<StackPanel>
<ComboBox Width="90"
SelectedIndex="0"
SelectionChanged="ComboBox_SelectionChanged"
Margin="0,0,0,0">
<ComboBoxItem Content=" -- Select --"/>
<ComboBoxItem Content="File"/>
<ComboBoxItem Content="Name"/>
</ComboBox>
</StackPanel>
</GridViewColumn.Header>
But because my Style that i am using contains TextBlock i cannot see this Combobox.
If i removed the Style ListViewHeaderDefaultStyle this works fine but then all my Header borders that i want to remove visible again.
How can i use this style and also display my Header Combobox ?
try this style
<Style x:Key="ListViewHeaderDefaultStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Border BorderThickness="0,0,0,1" BorderBrush="{DynamicResource GridViewColumnHeaderBorderBrushColor}" Background="Transparent">
<Grid>
<TextBlock x:Name="ContentHeader"
Text="{TemplateBinding Content}"
Padding="0,5,0,0"
Width="{TemplateBinding Width}"
TextAlignment="Left"
FontSize="13"
Margin="5,0,0,0">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ContentPresenter}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Foreground" Value="{DynamicResource GridViewColumnHeaderForegroundColor}"/>
<Setter Property="FontFamily" Value="{DynamicResource applicationFontFamily}"/>
<Setter Property="FontSize" Value="{DynamicResource GridViewColumnHeaderFontSize}"/>
</Style>
The application I'm working on has a surfacelistbox whose scrollbar I'm trying to style, but for some reason nothing I'm doing is affecting it.
The style:
<Style TargetType="s:SurfaceScrollBar">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="s:SurfaceScrollBar">
<Grid x:Name="Root">
<Track Margin="2,6,6,6"
Name="PART_Track"
Grid.Row="1"
IsDirectionReversed="true">
<Track.DecreaseRepeatButton>
<s:SurfaceRepeatButton Command="ScrollBar.PageUpCommand" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<s:SurfaceThumb Width="10"/>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<s:SurfaceRepeatButton Command="ScrollBar.PageDownCommand" />
</Track.IncreaseRepeatButton>
</Track>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="s:SurfaceRepeatButton">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="s:SurfaceRepeatButton">
<Border Background="Transparent"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type s:SurfaceThumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="s:SurfaceThumb">
<Border CornerRadius="5"
Background="DimGray"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I've tried putting this style in app.xaml, in the window's resources, and in the resources of the listbox itself (<s:SurfaceListBox.Resources>), but nothing has any visual effect. However, if I change it to a regular listbox and change the style accordingly (surfaceScrollBar to ScrollBar, etc.), the style is applied fine no matter where I put it, but this breaks touch scrolling.
Am I doing something wrong with the style itself?
<Style x:Key="Body_Content_DataGrid_Centering" TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" Value="DarkGray" />
<Setter Property="BorderThickness" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I have included above code in App.xaml file. But the trigger function never triggers on DataGrid cell focus. Can anyone explain why this happens?
Try use FocusVisualStyle. With it, you can set the focus frame and additional values.
Sample:
<!-- CellFocusVisual -->
<Style x:Key="CellFocusVisual" TargetType="{x:Type Control}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Control}">
<Border SnapsToDevicePixels="True" CornerRadius="0" BorderThickness="2" BorderBrush="#7B2F81" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- DataGridCell -->
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="BorderBrush" Value="{x:Null}" />
<Setter Property="FocusVisualStyle" Value="{StaticResource CellFocusVisual}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border x:Name="BackgroundBorder" BorderThickness="3" Background="Transparent">
<ContentPresenter VerticalAlignment="Center" Margin="4,0,6,0" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Focuses are different. See the link for more information.
Hi I try make a style with rounded corners for label and expander control.
Label style:
<Style x:Key="InfoLabelStyle" TargetType="{x:Type Label}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Label}">
<Border Name="Border" Background="#BFE3FE" BorderBrush="#BFE3FE" BorderThickness="1" CornerRadius="7" Padding="3">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="Height" Value="25"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="#BFE3FE"/>
<Setter Property="Background" Value="#BFE3FE"/>
<Setter Property="Margin" Value="2,4,0,1" />
<Setter Property="Padding" Value="4,0,0,0" />
</Style>
I use multibinding on this style in view:
<Label Style="{StaticResource InfoLabelStyle}">
<Label.Content>
<MultiBinding StringFormat="{}{0}, {1} rokov">
<Binding Path="Oponent.Info.Sex" Converter="{StaticResource sexConverter}"/>
<Binding Path= "Oponent.Info.Age"/>
</MultiBinding>
</Label.Content>
</Label>
But if I run app, content of this label is empty, binding is good, I try it on textBox control and work.
Second problem is, I would like have also rounded corners on expander control.
I try same way as in label style:
<Style x:Key="InfoExpanderStyle" TargetType="{x:Type Expander}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Expander}">
<Border Name="Border" Background="#BFE3FE" BorderBrush="#BFE3FE" BorderThickness="1" CornerRadius="7" Padding="3">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Applu style on Expander control:
<Expander Name="InfoExapnder"
Header="{Binding Path=Oponent.Info.Nick, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource InfoExpanderStyle}"
IsExpanded="True"
FontSize="18"
FontWeight="Normal"
Background="#ECEBEB"
Margin="3,0,3,0"
Grid.Row="0">
<Grid>
</Grid>
But result is same, empty content of the control.
What I do bad?
The label is empty because you've re-templated it but not specified where the content should be placed. You want something like:
<ControlTemplate TargetType="{x:Type Label}">
<Border Name="Border" Background="#BFE3FE" BorderBrush="#BFE3FE" BorderThickness="1" CornerRadius="7" Padding="3">
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Border>
</ControlTemplate>