I need access to borderbrush from code, how can bind?
This not work:
BorderBrush="{Binding color}"
<Border x:Name="brd" Background="Black" BorderBrush="White" BorderThickness="2" CornerRadius="3">
Here my xaml.
<UserControl x:Class="window6.Kbd"
x:Name="teclado"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:fps="clr-namespace:FPS.VirtualKeyboard;assembly=FPS.VirtualKeyboard"
mc:Ignorable="d" d:DesignWidth="418" Width="Auto" d:DesignHeight="177.326" Height="Auto" >
<Grid d:LayoutOverrides="VerticalMargin">
<fps:VirtualKeyboard x:Name="virtualKeyboard" BorderBrush="{Binding Color1}" >
<fps:VirtualKeyboard.Resources>
<fps:GetCharacterDependsOnSpecialKeysConverter x:Key="GetCharacterDependsOnSpecialKeysConverter"/>
<DataTemplate DataType="{x:Type fps:RegularKey}">
<Canvas>
<RepeatButton
Focusable="False"
Content="{Binding .}"
Canvas.Left="{Binding Left}"
Canvas.Top="{Binding Top}"
Width="{Binding Width}"
Height="{Binding Height}"
Command="fps:VirtualKeyboard.ClickCommand">
<RepeatButton.ContentTemplate>
<DataTemplate>
<Grid>
<ContentControl Content="{Binding ., Converter={StaticResource GetCharacterDependsOnSpecialKeysConverter}}">
<ContentControl.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding .}"/>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</Grid>
</DataTemplate>
</RepeatButton.ContentTemplate>
</RepeatButton>
</Canvas>
</DataTemplate>
<DataTemplate DataType="{x:Type fps:SpecialKey}">
<Canvas>
<RepeatButton x:Name="btn" Focusable="False" Content="{Binding .}" Canvas.Left="{Binding Left}" Canvas.Top="{Binding Top}" Width="{Binding Width}" Height="{Binding Height}" Command="fps:VirtualKeyboard.ClickCommand">
<RepeatButton.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding Content}" TextWrapping="Wrap"/>
</DataTemplate>
</RepeatButton.ContentTemplate>
</RepeatButton>
</Canvas>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsLocked}" Value="True">
<Setter Property="BorderBrush" Value="Yellow" TargetName="btn"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate DataType="{x:Type fps:NumPadKey}">
<Canvas>
<RepeatButton x:Name="btn" Focusable="False" Content="{Binding .}" Canvas.Left="{Binding Left}" Canvas.Top="{Binding Top}" Width="{Binding Width}" Height="{Binding Height}" Command="fps:VirtualKeyboard.ClickCommand">
<RepeatButton.ContentTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Left">
<TextBlock Text="{Binding NumCase}" Foreground="Red" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Content}" TextWrapping="Wrap" HorizontalAlignment="Left"/>
</StackPanel>
</DataTemplate>
</RepeatButton.ContentTemplate>
</RepeatButton>
</Canvas>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsLocked}" Value="True">
<Setter Property="BorderBrush" Value="Red" TargetName="btn"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<Style TargetType="{x:Type RepeatButton}" >
<Setter Property="Foreground" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Grid >
<Border x:Name="brd" Background="Black" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="2" CornerRadius="3">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsMouseOver" Value="True">
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" TargetName="brd" Value="Gray"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</fps:VirtualKeyboard.Resources>
</fps:VirtualKeyboard>
</Grid>
Like this?
brd.BorderBrush = new SolidColorBrush(Colors.Blue);
If you need to bind to another property, then:
brd.SetBinding(Border.BorderBrushProperty, new Binding("SomeProperty") { Source = someObject });
[Edit] Attempt #3 :)
Not sure I understand completely, but this is probably what you are looking for:
BorderBrush="{TemplateBinding BorderBrush}"
Now set BorderBrush of your RepeatButton and it should work.
Related
I am trying to copy the IntelliJ Titlebar Menu in Windows as a learning exercise.
The default color changes of a WPF MenuItem seem to be:
Low Opacity blue background when "IsMouseOver" and not "IsSubmenuOpen"
Low Opacity blue background when "IsSubmenuOpen"
I would like to change this behavior to this (which can be observed in IntelliJ):
No color change when "IsMouseOver" and not "IsSubmenuOpen"
Dark blue background when "IsSubmenuOpen"
White foreground when "IsSubmenuOpen"
I have found code in this answer which is capable of doing this, but it also seems to disable the ability of the MenuItem to open its drop down box to reveal its children.
<Style x:Key="TitleBarMenuItem" TargetType="{x:Type MenuItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding Header}" Margin="35 5 10 5" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSubmenuOpen" Value="True">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Background" Value="#2675BF"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
How can I get these color changes without disabling the MenuItem functionality?
The problem you have there is that there's no popup for the sub menu. You're missing something like:
<Popup x:Name="Popup"
Placement="Right"
HorizontalOffset="-4"
IsOpen="{TemplateBinding IsSubmenuOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Fade">
<Border x:Name="SubmenuBorder"
SnapsToDevicePixels="True"
Background="{DynamicResource MenuPopupBrush}"
BorderThickness="1">
<Border.BorderBrush>
<SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
</Border.BorderBrush>
<ScrollViewer CanContentScroll="True"
Style="{StaticResource MenuScrollViewer}">
<StackPanel IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Cycle" />
</ScrollViewer>
</Border>
</Popup>
Note that "IsItemsHost".
If you take a look at the templates for menu and menuitem you will notice it is very complicated stuff.
The approach I prefer is to work with content. You can put pretty much anything you like in a menuitem header.
One app I have does so with hard coded xaml. That's easier to understand than binding anyhow. Part of it looks like:
<MenuItem Header="_Layers" Style="{x:Null}">
<MenuItem>
<MenuItem.Header>
<CheckBox IsChecked="{Binding ShowBackground, Mode=TwoWay}">
_Background
</CheckBox>
</MenuItem.Header>
<MenuItem>
<MenuItem.Header>
<StackPanel Width="160">
<TextBlock Text="Opacity" />
<Slider Value="{Binding BackgroundOpacity, Mode=TwoWay}" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
</MenuItem>
<MenuItem>
<MenuItem.Header>
<CheckBox IsChecked="{Binding AppSettings.ShowElevationMap, Mode=TwoWay}">
_Elevation Map
</CheckBox>
</MenuItem.Header>
<MenuItem>
<MenuItem.Header>
<StackPanel Width="160">
<TextBlock Text="Opacity" />
<Slider
Value="{Binding AppSettings.ElevationOpacity, Mode=TwoWay}" />
</StackPanel>
</MenuItem.Header>
Layers is a top level menu item. These are templated different to their children. ( Did I mention menus are complicated ).
I offset the content so I don't need to worry about the icon column in the grid.
The styling I have might be useful to get you started.
You said this was a learning exercise so just doing it for you is presumably not exactly going to exercise your learning.
<ItemsPanelTemplate x:Key="MenuItemPanelTemplate">
<StackPanel Margin="-20,0,0,0" Background="White"/>
</ItemsPanelTemplate>
<Style TargetType="MenuItem" x:Key="MenuItemNoIcon">
<Setter Property="ItemsPanel" Value="{StaticResource MenuItemPanelTemplate}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
<Style TargetType="{x:Type MenuItem}" x:Key="{x:Type MenuItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{x:Static SystemColors.MenuBarBrush}"
SnapsToDevicePixels="True">
<Grid Margin="-1, 2, 0, 2">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="MenuItemIconColumnGroup" Width="0"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}"
Grid.Column="2" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
<TextBlock Grid.Column="4" Margin="{TemplateBinding Padding}" Opacity="0.7" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/>
<Path x:Name="RightArrow" Grid.Column="5" Width="10" Data="M0,0L4,3.5 0,7z" Fill="#FF212121" Margin="8,0,2,0" VerticalAlignment="Center"/>
<Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" HorizontalOffset="-2"
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right" VerticalOffset="-3">
<Border x:Name="SubMenuBorder" BorderBrush="#FF999999" BorderThickness="1" Background="#FFF0F0F0" Padding="2">
<ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
<Grid RenderOptions.ClearTypeHint="Enabled">
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle"
Grid.IsSharedSizeScope="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
</Grid>
</ScrollViewer>
</Border>
</Popup>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation" Value="True">
<Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
<Setter Property="Background" TargetName="templateRoot" Value="Transparent"/>
<Setter Property="BorderBrush" TargetName="templateRoot" Value="#FF26A0DA"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="#FF707070"/>
<Setter Property="Fill" TargetName="RightArrow" Value="#FF707070"/>
</Trigger>
<DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}}" Value="0">
<Setter Property="Visibility" TargetName="RightArrow" Value="Collapsed"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I have a ComboBox,
<ComboBox Grid.Row="1"
Margin="5"
ItemsSource="{Binding PreviousGroups, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding SelectedGroup, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Style="{DynamicResource CBComboBoxStyle}"
ItemContainerStyle="{DynamicResource CBItemContainerStyle}">
<ComboBox.ItemTemplate>
<DataTemplate>
<objects:GroupNameObject GroupName="{Binding Path=Name}"
LastChecked="{Binding Path=LastVerified, StringFormat='dd - MM - yyyy |T| hh : mm : ss'}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
which uses the item template GroupNameObject
<UserControl x:Class="MyProject.Objects.GroupNameObject"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:fa="http://schemas.awesome.incremented/wpf/xaml/fontawesome.sharp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Name="groupNameObject">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyProject;component/Assets/Colors.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Border Padding="3"
CornerRadius="10"
Margin="3"
HorizontalAlignment="Stretch">
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background"
Value="Transparent" />
</Style>
</Border.Style>
<StackPanel Orientation="Horizontal">
<Grid Width="40"
Height="40"
Margin="5 2 3 2">
<Border CornerRadius="10"
Background="{Binding Path=Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBoxItem}}}" />
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<fa:IconImage Icon="Folder"
Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBoxItem}}}"
Width="30" />
</StackPanel>
</Grid>
<StackPanel>
<TextBlock Text="{Binding Path=GroupName, ElementName=groupNameObject}"
FontSize="20"
FontWeight="Bold"
Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBoxItem}}}"
Margin="5 0" />
<TextBlock FontSize="12"
Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBoxItem}}}"
Margin="5 3">
<Run Text="{Binding Path=LastChecked, ElementName=groupNameObject, StringFormat='MM / dd / yyyy |T| HH : mm : ss'}" />
</TextBlock>
</StackPanel>
</StackPanel>
</Border>
with the ItemContainerStyle
<Style x:Key="CBItemContainerStyle"
TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment"
Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="VerticalContentAlignment"
Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="Padding"
Value="3,0,3,0" />
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border x:Name="Bd"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted"
Value="true">
<Setter Property="Background"
Value="{DynamicResource LemonCurry}" />
<Setter Property="Foreground"
Value="{DynamicResource LogoBlue}" />
</Trigger>
<Trigger Property="IsEnabled"
Value="false">
<Setter Property="Background"
Value="{DynamicResource PansyPurple}" />
<Setter Property="Foreground"
Value="{DynamicResource LemonCurry}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
When Built the DropDownItems inherit the Background and Foreground items correctly But the Displayed Item doesn't.
Display Item Example
DropDown Items Example
How Can I Change the Background and Foreground of the Displayed Item?
Edit:
Finally found a work around. instead of Binding the foreground and background of the GroupNameObject to the ComboBoxItem, I bound it to The ComboBox.
<StackPanel Orientation="Horizontal">
<Grid Width="40"
Height="40"
Margin="5 2 3 2">
<Border CornerRadius="10"
Background="{Binding Path=Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}}" />
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<fa:IconImage Icon="Folder"
Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}}"
Width="30" />
</StackPanel>
</Grid>
<StackPanel>
<TextBlock Text="{Binding Path=GroupName, ElementName=groupNameObject}"
FontSize="20"
FontWeight="Bold"
Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}}"
Margin="5 0" />
<TextBlock FontSize="12"
Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}}"
Margin="5 3">
<Run Text="{Binding Path=LastChecked, ElementName=groupNameObject, StringFormat='MM / dd / yyyy |T| HH : mm : ss'}" />
</TextBlock>
</StackPanel>
</StackPanel>
and in the ItemContainerStyle I changed the Highlight Color to a diffrent shade so it doesn't clash with the ComboBox Colors.
<Trigger Property="IsHighlighted"
Value="true">
<Setter Property="Background"
Value="{DynamicResource BlueSapphire}" />
</Trigger>
Display Item After
DropDown Items After
You may have to override the ComboBox Template Property as well:
Example
<Style TargetType="ComboBox" BasedOn="{StaticResource baseStyle}">
<Setter ... />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid
x:Name="templateRoot"
UseLayoutRounding="True"
SnapsToDevicePixels="True"
>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="18" />
</Grid.ColumnDefinitions>
<Popup>
...
</Popup>
<ToggleButton>
...
</ToggleButton>
<ContentPresenter
x:Name="contentPresenter"
Grid.Column="0"
...
/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
Inside this ToggleButton is the Layout for your ComboBox
I am trying to Create a Custom Control by extending the DataGrid in WPF, but the problem is that when I use this custom control in view and Provide the specific columns by setting the AutoGenerateColumns to False, the columns is not getting generated. In the OnApplyTemplate() when I tried to fetch the Datagrid through the Template it shows as column count as 0, whereas in the view in code behind it shows the no of columns correctly whatever is specified in the xaml.
Where I am wrong or something extra needs to be set for this?
My Custom control code-
public class DataGridControl: DataGrid
{
static DataGridControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DataGridControl), new FrameworkPropertyMetadata(typeof(DataGridControl)));
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
DataGrid dataGrid = Template.FindName("PART_DataGrid", this) as DataGrid;
int noOfColumns = dataGrid.Columns.Count// (0 it should come as 3)
}
}
Generic.xaml(inside the Control Template and border)
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
.....
xmlns:local="clr-namespace:Siemens.WPF.DataGridControl">
<LinearGradientBrush x:Key="lightBrushBack" EndPoint="0.5,1" StartPoint="0.5,0">
.....
</LinearGradientBrush>
<LinearGradientBrush x:Key="normalBrushBack" EndPoint="0.5,1" StartPoint="0.5,0">
......
</LinearGradientBrush>
<Style TargetType="{x:Type local:DataGridControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:DataGridControl}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<DataGrid x:Name="PART_DataGrid"
ItemsSource="{TemplateBinding ItemsSource}"
AutoGenerateColumns="{TemplateBinding AutoGenerateColumns}">
<DataGrid.Resources>
<!--A custom DataGridColumnHeadersPresenter is required to "not" display the custom ColumnHeader template as background of the datagrid header-->
<Style TargetType="{x:Type DataGridColumnHeadersPresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeadersPresenter}">
<Grid>
<!--"part_fillercolumnheader" (DataGridColumnHeader type) is removed, and a plain rectangle is placed in its place.-->
<Rectangle Fill="{StaticResource normalBrushBack}" />
<!--Leave the item presenter in its place.-->
<ItemsPresenter x:Name="itemsPresenter" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--End of custom DataGridColumnHeadersPresenter template-->
<!--Custom Column Header Gripper styling-->
<Style x:Key="ColumnHeaderGripperStyle" TargetType="{x:Type Thumb}">
<Setter Property="Width" Value="3"/>
<Setter Property="Foreground" Value="Transparent" />
<Setter Property="Cursor" Value="SizeWE"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Foreground}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--Custom Column Header template to show extra elements in the header-->
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<!--Let's keep the top section grid to contain the DataGridHeaderBorder, and left+right thumbs.-->
<Grid x:Name="fullHeader" Background="{StaticResource normalBrushBack}">
<!--Here is the theme based DataGridHeaderBorder. I've used Aero here.-->
<aero:DataGridHeaderBorder x:Name='HeaderBorder'
SortDirection="{TemplateBinding SortDirection}"
IsHovered="{TemplateBinding IsMouseOver}"
IsPressed="{TemplateBinding IsPressed}"
IsClickable="{TemplateBinding CanUserSort}"
BorderThickness="0,0,1,1"
BorderBrush="{TemplateBinding Foreground}"
Background="Transparent"
SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
SeparatorBrush="#FFC9CACA">
<!--Put 3 elements inside the border: Content of header, a drop down button, and a sort order indicator.-->
<Grid Margin="0,0,0,0">
<Grid.RowDefinitions>
<RowDefinition MinHeight="15" Height="20" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<!--For ContentPresenter-->
<ColumnDefinition Width="*" />
<!--For drop down button-->
<ColumnDefinition Width="23" />
<!--For sort order indicator-->
<ColumnDefinition Width="12" />
</Grid.ColumnDefinitions>
<!--A hidden rectangle is placed to be shown when mouse hovers on the column (to highlight the column.)-->
<Rectangle x:Name="HoverRectangle"
Stretch="Fill"
Grid.ColumnSpan="3"
Fill="{StaticResource lightBrushBack}"
Opacity="0"
StrokeThickness="0" />
<!--Content of the header.-->
<ContentPresenter Grid.Column="0"
Grid.Row="0"
Margin="2,0,0,0"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Cursor="{TemplateBinding Cursor}" />
<!--A drop down filter button.-->
<Button x:Name="PART_FilterBtn"
HorizontalAlignment="Right"
Command="{Binding FilterClickCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridControl}}}"
CommandParameter="{Binding ElementName=HeaderBorder}"
Grid.Row="0" Cursor="Hand"
Grid.Column="1">
<Button.Template>
<ControlTemplate>
<Path Data="M 0,0 L 1,1 1,3 2,3 2,1 3,0 Z"
Stretch="UniformToFill"
Stroke="{TemplateBinding Foreground}"
Fill="{TemplateBinding Foreground}"
Margin="4,4,0,4"/>
</ControlTemplate>
</Button.Template>
</Button>
<Path x:Name="PART_SortArrow"
Grid.Column="2"
HorizontalAlignment="Center" VerticalAlignment="Center"
Width="8"
RenderTransformOrigin=".5,.5"
Visibility="Visible"
Fill="{TemplateBinding Foreground}"
Stretch="Uniform"
Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z">
</Path>
</Grid>
</aero:DataGridHeaderBorder>
<Thumb x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" Style="{StaticResource ColumnHeaderGripperStyle}" />
<Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{StaticResource ColumnHeaderGripperStyle}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="SortDirection" Value="Descending">
<Setter TargetName="PART_SortArrow" Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="180" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property='IsMouseOver' SourceName="fullHeader" Value='True'>
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation BeginTime="00:00:00" Duration="00:00:00.20000"
Storyboard.TargetName="HoverRectangle"
Storyboard.TargetProperty="(UIElement.Opacity)"
To='1.0' />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation BeginTime="00:00:00" Duration="00:00:00.20000"
Storyboard.TargetName="HoverRectangle"
Storyboard.TargetProperty="(UIElement.Opacity)"
To='0' />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush options:Freeze="True" StartPoint="0.504,0.03" EndPoint="0.504,1.5">
<GradientStop Offset="0.0" Color="#E3F7FF" />
<GradientStop Offset="0.3" Color="#E3F7FF" />
<GradientStop Offset="0.35" Color="#BCECFE" />
<GradientStop Offset="1.0" Color="#B9E9FC" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush" Value="#69BBE3" />
</DataTrigger>
</Style.Triggers>
</Style>
<!--End of custom DataGridColumnHeader template-->
</DataGrid.Resources>
</DataGrid>
<Popup x:Name="PART_PopUp"
Grid.Column="3"
AllowsTransparency="True"
AllowDrop="True"
Width="200"
Height="253"
MinHeight="253"
MaxHeight="253"
PopupAnimation="Slide"
VerticalOffset="-15"
IsOpen="{Binding IsFilterPopUpVisible,RelativeSource={RelativeSource AncestorType=local:DataGridControl}}"
PlacementTarget="{Binding ElementName=PART_FilterBtn}"
StaysOpen="False"
Placement="Mouse" >
<Border Background="White" BorderBrush="DarkGray" BorderThickness="2">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="10,5,0,5">
<Button Margin="10,0,0,0" Name="PART_SelectAllBtn" Command="{Binding SelectAllClickCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridControl}}}" CommandParameter="{Binding ElementName=PART_ListBox}" >
<Button.Template>
<ControlTemplate>
<TextBlock Text="Select All" Foreground="Blue" Cursor="Hand" />
</ControlTemplate>
</Button.Template>
</Button>
<Button Margin="30,0,0,0" Name="PART_SelectNoneBtn" Command="{Binding SelectNoneClickCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridControl}}}" CommandParameter="{Binding ElementName=PART_ListBox}" >
<Button.Template>
<ControlTemplate>
<TextBlock Text="Select None" Foreground="Blue" Cursor="Hand" />
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<TextBox x:Name="PART_TextBox" Width="185" Height="25" Text="" Margin="3,0,3,3"/>
<ListBox x:Name="PART_ListBox"
Height="160"
MaxHeight="160"
MinHeight="160"
Width="185"
SelectionMode="Multiple"
DisplayMemberPath="Value"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
ItemsSource="{Binding FilterCollectionList, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridControl}}}" Margin="0,0,0,5"
ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem" >
<CheckBox x:Name="PART_CheckBox" Margin="5,2" IsChecked="{Binding IsSelected}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding CheckedCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridControl}}}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding CheckedCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridControl}}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ContentPresenter />
</CheckBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<StackPanel Orientation="Horizontal" Margin="0,0,0,15" HorizontalAlignment="Center">
<Button x:Name="PART_OkBtn" Height="22" Width="70" Content="Ok"
IsEnabled="{Binding IsOkButtonEnabled, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridControl}}}"
Command="{Binding OkButtonClickCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridControl}}}"
/>
<Button x:Name="PART_CancelBtn" Height="22" Width="70" Content="Cancel" Margin="5,0,0,0"
Command="{Binding CancelButtonClickCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridControl}}}"
/>
</StackPanel>
</StackPanel>
</Border>
</Popup>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
MainWindow.xaml
<dataGrid:DataGridControl x:Name="dataGridControl" AutoGenerateColumns="False">
<dataGrid:DataGridControl.Columns>
<DataGridTextColumn Header="RollNo" Binding="{Binding RollNo}" />
<DataGridTextColumn Header="Name" Binding="{Binding Name}" />
<DataGridTextColumn Header="FirstName" Binding="{Binding FirstName}" />
</dataGrid:DataGridControl.Columns>
</dataGrid:DataGridControl>
MainWindow.xaml.cs
public MainWindow()
{
InitializeComponent();
List<Student> studList =
new List<Student>() { new Student { RollNo = 1, Name = "Full Name
1", FirstName = "FirstName1", LastName="LastName1", Address =
"Pune1", PinCode= "411057"},};
dataGridControl.ItemsSource = studList;
int noOfColumns = dataGridControl.Columns.Count; //(showing 3 as expected)
}
Create property for custom control
#region GridColumns
private ObservableCollection<DataGridColumn> _gridColumns;
public ObservableCollection<DataGridColumn> GridColumns
{
get => _gridColumns;
}
#endregion GridColumns
Add columns from created property using method OnApplyTemplate
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (!AutoGenerateColumns)
{
var grid = GetTemplateChild("PART_Grid") as DataGrid;
foreach (var column in _gridColumns)
grid.Columns.Add(column);
}
}
Change MainWindow.xaml
<dataGrid:DataGridControl x:Name="dataGridControl" AutoGenerateColumns="False">
<dataGrid:DataGridControl.GridColumns>
<DataGridTextColumn Header="RollNo" Binding="{Binding RollNo}" />
<DataGridTextColumn Header="Name" Binding="{Binding Name}" />
<DataGridTextColumn Header="FirstName" Binding="{Binding FirstName}" />
</dataGrid:DataGridControl.GridColumns>
</dataGrid:DataGridControl>
I'm trying to add rounded windows so that view looks from this:
To this:
There are a few similar questions online that say change the WindowStyle to None and AllowsTransparency=True with a Border tag as seen below.
<Window x:Class="SIDD.EmailComposerWindow"
...
Height="460.316"
Width="733.167"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
AllowsTransparency="True"
ResizeMode="CanResize"
<Border Background="White" BorderBrush="Black" BorderThickness="1,1,1,1" CornerRadius="30,30,30,30">
<Grid>
</Grid>
</Border>
>
<Window.Background>
<SolidColorBrush Opacity="0" />
</Window.Background>
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="{Binding ActualHeight,ElementName=TitleBar}"
GlassFrameThickness="0"
/>
</WindowChrome.WindowChrome>
<Window.DataContext>
<localvm:EmailComposerViewModel />
</Window.DataContext>
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="{StaticResource WindowBrush}"/>
</Style>
</Window.Style>
<Window.Resources>
<SolidColorBrush x:Key="WindowBrush" Color="White"/>
<Style x:Key="VerticalSeparatorStyle"
TargetType="{x:Type Separator}"
BasedOn="{StaticResource {x:Type Separator}}">
<Setter Property="Margin" Value="6,0,6,0"/>
<Setter Property="LayoutTransform">
<Setter.Value>
<TransformGroup>
<TransformGroup.Children>
<TransformCollection>
<RotateTransform Angle="90"/>
</TransformCollection>
</TransformGroup.Children>
</TransformGroup>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonLinkStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Margin" Value="2,4,2,4" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Foreground" Value="Blue" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border" BorderThickness="0" BorderBrush="Transparent">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="White"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Foreground" Value="DarkGoldenrod"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<BooleanToVisibilityConverter x:Key="BoolToVis"/>
<Style x:Key="SearchButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Margin" Value="2,4,2,4" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Foreground" Value="Blue" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="border" BorderThickness="0" BorderBrush="Transparent">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="White"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Foreground" Value="DarkGoldenrod"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Image x:Key="SearchIcon" Source="../Images/Search.png" Height="15px" Width=" 15px"/>
<Image x:Key="ResetIcon" Source="../Images/CancelX.png" Height="15px" Width="15px"/>
<Style x:Key="PaneBorderStyle" TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="10,10,10,10"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Margin" Value="0,0,0,0"/>
<Setter Property="Background" Value="WhiteSmoke"/>
</Style>
</Window.Resources>
<!-- Content Layout -->
<DockPanel Margin="10,10,10,10">
<!-- Header -->
<Border Background="Blue" Style="{DynamicResource PaneBorderStyle}" CornerRadius="15,15,0,0">
<Grid>
<TextBlock HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="textBlock_From" Width="283" />
</Grid>
</Border>
<!-- Body -->
<Grid DockPanel.Dock="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="77*"/>
<ColumnDefinition Width="64*"/>
<ColumnDefinition Width="141*"/>
<ColumnDefinition Width="140*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<!-- Left panel -->
<Border Style="{DynamicResource PaneBorderStyle}" Margin="0,0,0,0" Grid.ColumnSpan="2" >
<DockPanel VerticalAlignment="Top">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
<Label VerticalAlignment="Center" Content="Email from:" Opacity="0.6" FontFamily="Levenim MT" Width="100" />
<TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" VerticalAlignment="Center" Text="{Binding Ticket.CustomerName}" />
</StackPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
<Label Content="Case:" OpacityMask="Black" Opacity="0.6" FontFamily="Levenim MT" Width="100" />
<TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" VerticalAlignment="Center" Text="{Binding Ticket.CaseDetails}" />
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" DockPanel.Dock="Top">
<Label Content="Account Details:" Opacity="0.6" FontFamily="Levenim MT" Width="100" />
<TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" VerticalAlignment="Center" Text="{Binding Ticket.AccountInfo}" />
</StackPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
<Label Content="Date:" Opacity="0.6" FontFamily="Levenim MT" Width="100" />
<TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" VerticalAlignment="Center" Text="{Binding Ticket.MessageDate}" />
</StackPanel>
<Rectangle Fill="#FFF4F4F5" Stroke="Black" DockPanel.Dock="Top" Opacity="0.2" Margin="0,5,0,5"/>
<TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" Text="{Binding Ticket.MessageContent}" TextWrapping="Wrap" DockPanel.Dock="Top" />
</DockPanel>
</Border>
<!-- Center panel -->
<Border Style="{DynamicResource PaneBorderStyle}" CornerRadius="10,0,0,10" Grid.Column="2" Background="White" Width="Auto">
<DockPanel LastChildFill="True">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
<Label VerticalAlignment="Center" Content="To" Opacity="0.6" FontFamily="Levenim MT" Margin="5,0,0,0" />
<TextBox BorderThickness="0" IsReadOnly="True" Background="#E8F2FF" Text="{Binding Ticket.CustomerEmailAddress}" FontSize="12" VerticalAlignment="Center" />
</StackPanel>
<Rectangle Fill="#FFF4F4F5" Stroke="Black" DockPanel.Dock="Top" Opacity="0.2"/>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
<Label Content="Subject" Opacity="0.6" FontFamily="Levenim MT" Margin="5,0,0,0"/>
<TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" VerticalAlignment="Center" Text="{Binding Ticket.Subject}" />
</StackPanel>
<Rectangle Fill="#FFF4F4F5" Stroke="Black" DockPanel.Dock="Top" Opacity="0.2"/>
<ToolBar Margin="2" Background="LightGray" DockPanel.Dock="Top" Visibility="Collapsed">
<Button>1</Button>
<Button>2</Button>
<Button>3</Button>
<Button>4</Button>
<ComboBox SelectedIndex="0">
<ComboBoxItem>Style1</ComboBoxItem>
<ComboBoxItem>Style2</ComboBoxItem>
<ComboBoxItem>Style3</ComboBoxItem>
</ComboBox>
<Button>5</Button>
<Button>6</Button>
<Separator />
<Button>7</Button>
<Button>8</Button>
<Separator />
<Button>9</Button>
<Button>10</Button>
</ToolBar>
<RichTextBox Name="EditMessageBox" Margin="5,0,5,5" DockPanel.Dock="Top" Height="auto" BorderThickness="5" BorderBrush="{x:Null}" Background="White">
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0" />
</Style>
</RichTextBox.Resources>
</RichTextBox>
</DockPanel>
</Border>
<!-- Right panel -->
<Border Style="{DynamicResource PaneBorderStyle}" CornerRadius="0,10,10,0" Grid.Column="3">
<Grid Margin="2">
<DockPanel LastChildFill="True" RenderTransformOrigin="0.5,0.5">
<!-- suggestions -->
<Label Content="SUGGESTIONS" HorizontalAlignment="Left" DockPanel.Dock="Top" FontFamily="Levenim MT" Margin="0" Width="90.277" Opacity="0.6" />
<!-- snippet list -->
<Grid Height="Auto" x:Name="SnippetViewGrid">
<StackPanel x:Name="AccordianStack" Margin="0,0,0,10">
<!--Snippet Categories-->
<ItemsControl ItemsSource="{Binding ObservableSnippetCategories}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<custom:Accordian x:Name="Accordian" ButtonClick="Accordian_ButtonClick"
TemplateSelectCommand="{Binding TemplateSelectCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}"
TemplateShowCommand="{Binding TemplateShowCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}">
</custom:Accordian>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</Grid>
</DockPanel>
<!-- Searchbar -->
<DockPanel Margin="5,5,5,5" LastChildFill="True" Height="35.667" VerticalAlignment="Bottom">
<Border Margin="0,4,0,0" Width="Auto" CornerRadius="5,5,5,5" Background="White" BorderThickness="1" BorderBrush="Gray">
<Grid>
<Button x:Name="SearchTemplateButton" Content="{StaticResource SearchIcon}"
Command="{Binding SearchTemplatesCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}"
CommandParameter="{Binding Text, ElementName=SearchKey}"
Style="{StaticResource ButtonLinkStyle}" Opacity="0.5" HorizontalAlignment="Left" VerticalAlignment="Center"
/>
<TextBox x:Name="SearchKey" Text="" BorderThickness="0" Width="Auto" Background="White" Margin="21.724,4,20.999,4">
<TextBox.InputBindings>
<KeyBinding Key="Enter"
Command="{Binding SearchTemplatesCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}"
CommandParameter="{Binding Text, ElementName=SearchKey}"
/>
<KeyBinding Key="Esc"
Command="{Binding ResetSearchCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}"
/>
</TextBox.InputBindings>
</TextBox>
<Button x:Name="ResetSearchButton" Content="{StaticResource ResetIcon}"
Command="{Binding ResetSearchCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}"
Style="{DynamicResource SearchButton}" Opacity="0.5" Width="18.999" Height="Auto"
Margin="0,4,2,4" HorizontalAlignment="Right" VerticalAlignment="Center"
/>
</Grid>
</Border>
</DockPanel>
</Grid>
</Border>
</Grid>
</DockPanel>
However, with this added code, I get the error The property content is set more than once for the following code:
<!-- Header -->
<Border Background="Transparent" DockPanel.Dock="Top" x:Name="TitleBar">
<DockPanel LastChildFill="True" Margin="0,0" HorizontalAlignment="Center" DockPanel.Dock="Top" Height="20">
</DockPanel>
</Border>
Does anyone know why this is?
You have set twice the window style here:
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="{StaticResource WindowBrush}"/>
</Style>
And here:
WindowStyle="None"
I'm not close to a VS right now but it seems to be the problem.
I'm using C# WPF Application
I need your help.
If I press on a button it should be selected, but if I now press on another button it should be selected and the other button should not be selected.
It should show where the user is.The button should be selected until another button has been clicked.
But when you go with the mouse over, the normal mouse over effect should come.
<Window x:Name="windowsForm" x:Class="Vorschau.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Vorschau"
mc:Ignorable="d"
Title="Vorschaukomponente" Height="514.583" Width="805.208" FontFamily="Century Gothic" WindowStartupLocation="Manual" BorderThickness="0" ResizeMode="NoResize" WindowStyle="None" Icon="C:\Users\user\Documents\Visual Studio 2015\Projects\Vorschau\Vorschau\img\coordinates.ico" Background="{x:Null}" AllowsTransparency="True">
<Window.Resources>
<Style x:Key="border_res" TargetType="{x:Type Border}">
<Setter Property="Background" Value="#3A3A3B" />
<Setter Property="CornerRadius" Value="10" />
</Style>
</Window.Resources>
<Border Style="{StaticResource border_res}">
<Grid>
<Canvas HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="185" Background="#FFE57E31">
<Canvas Height="64" Canvas.Top="451" Width="185" Background="#FF2C373F">
<Label x:Name="lbCopyright" Content="© Name 2017" Canvas.Left="10" Canvas.Top="29" Width="121" Foreground="#FF1B1D1F"/>
</Canvas>
<Canvas Height="391" Canvas.Top="60" Width="185" Background="#FF37424A">
<Button x:Name="btVorschau" Content="Vorschau" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="185" Height="50" Foreground="LightGray" FontSize="16"
HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Click="Button_Click">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="#FF37424A"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FF303B43"/>
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button x:Name="btEinstellung" Content="Einstellung" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="185" Height="50" Foreground="LightGray" FontSize="16"
HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Canvas.Top="50" Click="btEinstellung_Click">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="#FF37424A"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FF303B43"/>
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</Canvas>
<Canvas Height="60" Canvas.Left="185" Width="618" Background="#FFEEE9ED">
<Label x:Name="lbClose" Content="X" Canvas.Left="578" FontSize="20" MouseDoubleClick="lbClose_MouseDoubleClick"/>
<Label x:Name="lbMinimize" Content="-" Canvas.Left="556" FontSize="22" Canvas.Top="-2" MouseDoubleClick="lbMinimize_MouseDoubleClick"/>
<Label x:Name="lbWhereIAm" Content="Label" Canvas.Left="10" Canvas.Top="15" Width="162" FontSize="20"/>
</Canvas>
<Canvas x:Name="canvasContent" Height="455" Canvas.Left="185" Canvas.Top="60" Width="618" Background="#FFD1CFD0">
<TabControl x:Name="tabControl" Height="241" Canvas.Left="93" Canvas.Top="87" Width="440" SelectedIndex="0" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<TabItem x:Name="tabitem1" Header="TabItem">
<Grid Background="#FFE5E5E5">
<Label x:Name="label1" Content="Label" HorizontalAlignment="Left" Margin="99,95,0,0" VerticalAlignment="Top" Background="#FF2387FF"/>
</Grid>
</TabItem>
<TabItem x:Name="tabitem2" Header="TabItem" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<Grid Background="#FFE5E5E5">
<Label x:Name="label" Content="Label" HorizontalAlignment="Left" Margin="138,124,0,0" VerticalAlignment="Top" Background="#FFF70000"/>
</Grid>
</TabItem>
</TabControl>
</Canvas>
<Image x:Name="image" Height="38" Canvas.Left="10" Canvas.Top="10" Width="38" Source="C:\Users\user\Documents\Visual Studio 2015\Projects\Vorschau\Vorschau\img\coordinatesWhite.png"/>
<Label x:Name="lbLogoname" Content="Vorschaukomponente" Canvas.Left="37" Canvas.Top="10" Width="143" FontWeight="Bold" Foreground="White"/>
</Canvas>
</Grid>
</Border>
</Window>
you can use Listbox , to show group of buttons
Solution 1 :
<Style TargetType="{x:Type ListBox}">
<Setter Property="ListBox.ItemTemplate">
<Setter.Value>
<DataTemplate>
<ToggleButton Content="{Binding}"
IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}"
/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Solution 2
Use radio button change the template
<RadioButton Content="Point" >
<RadioButton.Template>
<ControlTemplate>
<ToggleButton IsChecked="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"/>
</ControlTemplate>
</RadioButton.Template>
</RadioButton>