I have a Usercontrol: SnazzyForm, which in addition to a couple of borders and and a header area and whatnot, also has a Content Presenter which under .NET Framework 3.5 presented content passed to it in other forms that used the control just fine.
However after moving the project to 4.0 I am greeted with "Cannot add content to object of type" blah blah blah.
The codebehind for the control is thus:
Imports System
Imports System.IO
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.ComponentModel
Public Class SnazzyForm
Inherits ContentControl
Public Shared TitleProperty As DependencyProperty = DependencyProperty.Register("Title", GetType(String), GetType(SnazzyForm))
<Description("Title to display"), _
Category("Custom")> _
Public Property Title() As String
Get
Return CType(GetValue(TitleProperty), String)
End Get
Set(ByVal value As String)
SetValue(TitleProperty, value)
End Set
End Property
Shared Sub New()
' Insert code required on object creation below this point.
DefaultStyleKeyProperty.OverrideMetadata(GetType(SnazzyForm), New FrameworkPropertyMetadata(GetType(SnazzyForm)))
End Sub
End Class
The template in the resourcedictionary that governs this control is thus:
<Style TargetType="{x:Type local:SnazzyForm}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:SnazzyForm}">
<ControlTemplate.Resources>
<Style TargetType="{x:Type Border}" x:Key="formOuterBorderStyle">
<Setter Property="Margin" Value="22,22,22,3" />
<Setter Property="Padding" Value="0" />
<Setter Property="BorderBrush" Value="{StaticResource BrushBorder}" />
<Setter Property="BorderThickness" Value="3" />
<Setter Property="Background" Value="{StaticResource BrushBackgroundDark}" />
<Setter Property="CornerRadius" Value="20,20,0,0" />
</Style>
<Style TargetType="{x:Type TextBlock}" x:Key="formTitleStyle">
<Setter Property="Foreground" Value="{StaticResource BrushWhiteSmoke}" />
<Setter Property="FontFamily" Value="Verdana" />
<Setter Property="FontSize" Value="16" />
<Setter Property="Padding" Value="11,7,7,7" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
<Style TargetType="{x:Type TextBlock}" x:Key="formBreadcrumbStyle">
<Setter Property="Foreground" Value="{StaticResource BrushWhiteSmoke}" />
<Setter Property="FontFamily" Value="Verdana" />
<Setter Property="FontSize" Value="11" />
<Setter Property="Padding" Value="7" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
<Style TargetType="{x:Type Rectangle}" x:Key="formBackgroundRectangleStyle">
<Setter Property="Fill" Value="{StaticResource BrushABCLight}" />
</Style>
<Style TargetType="{x:Type Border}" x:Key="formTitleBorderStyle">
<Setter Property="BorderBrush" Value="{StaticResource BrushBlack}" />
<Setter Property="BorderThickness" Value="0,0,0,2" />
</Style>
</ControlTemplate.Resources>
<AdornerDecorator d:DesignWidth="640" d:DesignHeight="480">
<Grid Width="Auto" Height="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" FontFamily="Arial" FontSize="18.667" Foreground="#FFE0E0E0" Text="{TemplateBinding Title}" TextWrapping="Wrap" Panel.ZIndex="2" Visibility="Collapsed"/>
<Path Fill="Black" Stretch="Fill" Stroke="{x:Null}" Margin="0" VerticalAlignment="Stretch" Height="Auto" Grid.Column="1" Grid.Row="0" Data="M0.5,0.5 L39.5,39.5 0.5,39.5 z"/>
<Border Background="Black" Margin="0" VerticalAlignment="Stretch" Height="Auto" Grid.Row="0" CornerRadius="10,0,0,0"/>
<!-- <Rectangle Fill="Black" Stroke="Black" Margin="0" VerticalAlignment="Stretch" Height="Auto" Grid.Row="0"/> -->
<Rectangle Stroke="{x:Null}" Margin="0" Height="Auto" Opacity="0.5" Grid.ColumnSpan="2" Grid.Row="3" Grid.RowSpan="1">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF222222" Offset="0"/>
<GradientStop Color="#FFB3B3B3" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Fill="Black" Stroke="Black" Margin="0" Grid.ColumnSpan="2" Grid.Row="1"/>
<Rectangle Fill="{TemplateBinding Background}" Stroke="Black" Margin="0" Height="Auto" Panel.ZIndex="-7" Grid.ColumnSpan="2" Grid.Row="2" Grid.RowSpan="1"/>
<Border x:Name="bdr" Style="{StaticResource formOuterBorderStyle}" Margin="0" Grid.ColumnSpan="2" Grid.RowSpan="3" d:LayoutOverrides="Width, Height" d:IsHidden="True" Visibility="Collapsed"/>
<Grid Margin="3" Grid.ColumnSpan="2" Grid.RowSpan="3">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="77" />
<RowDefinition MinHeight="400" />
</Grid.RowDefinitions>
<Border Style="{StaticResource formTitleBorderStyle}" BorderBrush="{x:Null}">
<StackPanel Margin="0">
<TextBlock Text="{Binding ViewModelFriendlyName}" Style="{StaticResource formTitleStyle}" />
<TextBlock Margin="11,0,0,0" Text="{Binding BreadcrumbTrail}" Style="{StaticResource formBreadcrumbStyle}" />
</StackPanel>
</Border>
<Rectangle Grid.Row="1" Style="{StaticResource formBackgroundRectangleStyle}" Visibility="Collapsed" />
<!--Put the form below here-->
<ContentPresenter x:Name="ContentPresenterX" Grid.Row="1" Margin="0" />
<!--Put the form above here-->
</Grid>
</Grid>
</AdornerDecorator>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I guess I really just want to know why I now have to tell the control to use the contentpresenter to present the content, when previously it know that is what I wanted, and also how I do it.
Any thoughts?
Cory
Added Content={TemplateBinding Property=Content} to ContentPresenter.
MSDN Forum post regarding this issue suggested adding the ContentPropertyAttribute setter to the controls codebehind, but I could not get that to work.
Cory
Related
Application with an Dashboard.
The Dashboard uses Cards in the form of User Controls. These Controls weren't responsive so I put them into Viewboxes. Some Cards are working but some don't. Especially the Cards with DataGrids in them don't work for me. Maybe you can help me out.
DashboardView
Here is the DashboardPage:
<Page x:Class="Keppler.MES.Common.Pages.Dashboard"
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:sysglb="clr-namespace:System.Globalization;assembly=mscorlib"
xmlns:local="clr-namespace:Keppler.MES.Common.Pages"
xmlns:pageviewmodels="clr-namespace:Keppler.ViewModels.PageViewModels;assembly=Keppler.ViewModels" xmlns:controls="clr-namespace:Keppler.MES.Common.Pages.Controls"
mc:Ignorable="d"
Title="DashboardPage">
<Page.DataContext>
<pageviewmodels:VMDashboard/>
</Page.DataContext>
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Common\ResourceDictionaries\KepplerColorsAndBrushes.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="35"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
</Grid.RowDefinitions>
<controls:KepplerEffortCard PageName="Bookings" GroupedEfforts="{Binding EffortOfLastWorkDay}" EffortOfBindings="{Binding LastWorkDaysEffort}" JumpToLink="{Binding RequestPageChangeCommand}" Grid.Row="3" Grid.ColumnSpan="6" Grid.RowSpan="2"/>
<controls:KepplerEffortCard PageName="Bookings" GroupedEfforts="{Binding EffortOfLastWeek}" EffortOfBindings="{Binding LastWeeksEffort}" JumpToLink="{Binding RequestPageChangeCommand}" Grid.Column="6" Grid.Row="3" Grid.ColumnSpan="6" Grid.RowSpan="2"/>
<controls:KepplerOrdersCard PageName="Orders" Grid.ColumnSpan="12" Grid.Row="5" Grid.RowSpan="2" OrderBudgets="{Binding OrderBudgets}" JumpToLink="{Binding RequestPageChangeCommand}"/>
<controls:KepplerTurnOverCard Grid.Row="0" Grid.ColumnSpan="2" Header="{Binding TurnOverThisYear.Header}" TurnOver="{Binding TurnOverThisYear.TurnOver}" Grid.Column="0" Margin="10,0" />
<controls:KepplerTurnOverCard Grid.Row="0" Header="{Binding TurnOverLastYear.Header}" TurnOver="{Binding TurnOverLastYear.TurnOver}" Grid.Column="2" Grid.ColumnSpan="2" Margin="10,0" RenderTransformOrigin="0.5,0.5"/>
<controls:KepplerTurnOverCard Grid.Row="0" Grid.ColumnSpan="2" Header="{Binding TurnOverThisQuarter.Header}" TurnOver="{Binding TurnOverThisQuarter.TurnOver}" Grid.Column="4" Margin="10,0"/>
<controls:KepplerTurnOverCard Header="{Binding TurnOverThisMonth.Header}" TurnOver="{Binding TurnOverThisMonth.TurnOver}" Grid.ColumnSpan="2" Grid.Column="6" Grid.Row="0" Margin="10,0"/>
<Viewbox Grid.Row="1" Grid.Column="0" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerWarningCard PageName="Orders" WarningsInfo="{Binding BudgetWarning}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="2" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerWarningCard PageName="Invoices" WarningsInfo="{Binding InvoiceWarning}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="4" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerWarningCard PageName="Orders" WarningsInfo="{Binding ResourceWarning}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="6" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerWarningCard PageName="Orders" WarningsInfo="{Binding DeliveryWarning}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="8" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerWarningCard PageName="Orders" WarningsInfo="{Binding WorkloadWarning}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="10" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerBankingCard BankingsInfo="{Binding BankingsInfo}"/>
</Viewbox>
<controls:KepplerCustomerCard PageName="Customers" Grid.Row="7" Grid.RowSpan="2" Customers="{Binding Customers}" Grid.ColumnSpan="12" JumpToLink="{Binding RequestPageChangeCommand}"/>
<controls:KepplerProjectsCard PageName="Projects" Grid.ColumnSpan="12" Grid.Row="9" Grid.RowSpan="2" Projects="{Binding Projects}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Grid>
Here is the Control:
<UserControl x:Class="Keppler.MES.Common.Pages.Controls.KepplerOrdersCard"
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:local="clr-namespace:Keppler.MES.Common.Pages.Controls"
mc:Ignorable="d"
Name="OrderBudgetCard"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\..\Common\ResourceDictionaries\KepplerColorsAndBrushes.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Border CornerRadius="5" Margin="5" BorderThickness="0">
<Border.BitmapEffect>
<DropShadowBitmapEffect/>
</Border.BitmapEffect>
<Grid>
<Border x:Name="DBRounded" CornerRadius="5" BorderThickness="1" Background="#FF888888"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Border x:Name="Header" Grid.ColumnSpan="1" Grid.RowSpan="1" CornerRadius="5,5,0,0" BorderThickness="1">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFFAE00" Offset="0"/>
<GradientStop Color="#FFFFC500" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<Button Background="Transparent" Command="{Binding ElementName=OrderBudgetCard, Path=JumpToLink}" CommandParameter="{Binding ElementName=OrderBudgetCard, Path=PageName}" Grid.ColumnSpan="1" Grid.RowSpan="2">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border x:Name="border" Background="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"
BorderThickness="1" CornerRadius="5">
<ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FFFFAE00"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
<DataGrid x:Name="dgOrderBudgets"
Background="Transparent"
ItemsSource="{Binding ElementName=OrderBudgetCard, Path=OrderBudgets}"
AutoGenerateColumns="False"
HorizontalGridLinesBrush="Transparent"
VerticalGridLinesBrush="Transparent"
BorderBrush="Transparent"
IsReadOnly="True" Grid.RowSpan="2">
<DataGrid.RowHeaderStyle>
<Style TargetType="DataGridRowHeader">
<Setter Property="Background" Value="Transparent"/>
</Style>
</DataGrid.RowHeaderStyle>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Height" Value="auto"/>
<Setter Property="Margin" Value="5"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="Foreground" Value="black"/>
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Foreground" Value="darkred"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="order number" Width="200" Binding="{Binding Order.Number}"/>
<DataGridTextColumn Header="budget [€]" Width="120" Binding="{Binding Order.Subtotal,StringFormat=C2, ConverterCulture=de-DE}"/>
<DataGridTextColumn Header="consumed [€]" Width="*" Binding="{Binding EffortInCash,StringFormat=C2, ConverterCulture=de-DE}"/>
<DataGridTextColumn Header="state" Width="*" Binding="{Binding Order.Title}"/>
</DataGrid.Columns>
</DataGrid>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=DBRounded}"/>
</Grid.OpacityMask>
</Grid>
</Grid>
</Border>
I tried putting the other Controls into Viewboxes like the Warningcards, but I didnt get anything out of it. Doesnt matter if I used fill, uniform or uniformtofill.
I have a ListView with custom ItemContainer and ItemTemplate. ItemTemplate contains, among other controls, a button. Whenever I click or tap a button ListView a whole item is selected, in contrast to the expected button click or tap event to be fired. I've noticed that the only time the button is clickable is when I position mouse cursor at the top border of the button (whichi is also the only time I am getting the default mouse over effect).
Here is the XAML:
<Style TargetType="ListView" x:Key="SalesOrdersListViewStyle">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="SelectionMode" Value="Single" />
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListViewItem">
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
<!--<Setter Property="Background" Value="Transparent"/>-->
<Setter Property="TabNavigation" Value="Local"/>
<Setter Property="Padding" Value="12,6"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}"/>
<Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter
Foreground="{StaticResource HighlightPressedBrush}"
CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
ContentMargin="{TemplateBinding Padding}"
CheckMode="Inline"
ContentTransitions="{TemplateBinding ContentTransitions}"
CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
PointerOverForeground="{StaticResource HighlightPressedBrush}"
PressedBackground="{ThemeResource HighlightAlternativePressedBrush}"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
PointerOverBackground="{ThemeResource HighlightPointerOverBrush}"
ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
SelectedPressedBackground="{ThemeResource ControlBackgroundDarkBrush}"
SelectionCheckMarkVisualEnabled="True"
SelectedForeground="#FFFFFFFF"
SelectedPointerOverBackground="{ThemeResource HighlightAlternativePointerOverBrush}"
SelectedBackground="{ThemeResource HighlightPressedBrush}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
x:Uid="SalesOrderNumber"
Grid.Row="0" Grid.Column="1" />
<TextBlock
Grid.Row="0" Grid.Column="2"
Text="{Binding Number}" />
<!-- TEST BUTTON THAT CANNOT BE TAPPED -->
<Button
Grid.Row="0" Grid.RowSpan="4" Grid.Column="3"
HorizontalAlignment="Left" VerticalAlignment="Center"
Background="Red"
IsHitTestVisible="True"
Content="TEST" />
<TextBlock
x:Uid="DeliveryMode"
Grid.Row="1" Grid.Column="1" />
<TextBlock
Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2"
Text="{Binding DeliveryMode}" /
<TextBlock
x:Uid="ShippingDate"
Grid.Row="2" Grid.Column="1" />
<TextBlock
Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2"
Text="{Binding ShippingDate}" />
<TextBlock
x:Uid="ProjectNumber"
Grid.Row="3" Grid.Column="1" />
<TextBlock
Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2"
Text="{Binding ProjectNumber}" />
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
How do I make the button click or tap event to fire instead of selecting an item?
Note: I just commented out the entire <Setter Property="ItemContainerStyle"> and the issue is still there.
The problem is in you TextBlocks with Grid.Column="2" Grid.ColumnSpan="2". Set ColumSpan to 1 and it will work.
I am a total newbie but couldn't you just add a Button click event?
<Button
Grid.Row="0" Grid.RowSpan="4" Grid.Column="3"
HorizontalAlignment="Left" VerticalAlignment="Center"
Background="Red"
IsHitTestVisible="True"
Click"btn_Click"
Content="TEST" />
And in the code:
private void btn_Click(object sender, RoutedEventArgs e)
{
// Do stuff
}
I hope I don't talk bullsh*t here but I don't see your click event anywhere.
I have a Stackpanel with a Image in it. The Image is partly transperent.
So i want the Background to be Red, when the mouse is not over (which works). But wen the mouse is over it should turn into green. But it doesn't work. Can you please help me out.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework">
<Style x:Key="PhoenixWindowStyle" TargetType="{x:Type Window}">
<Setter Property="shell:WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome GlassFrameThickness="0"
ResizeBorderThickness="1"
CaptionHeight="32"
CornerRadius="0"/>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="{DynamicResource DefaultBackgroundBrush}"/>
<Setter Property="MinWidth" Value="100"/>
<Setter Property="MinHeight" Value="100"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid Background="{DynamicResource BorderBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
<RowDefinition Height="1"/>
</Grid.RowDefinitions>
<DockPanel Grid.Column="1" Grid.Row="0">
<TextBlock DockPanel.Dock="Left" Margin="0, 2, 0, 2" Padding="0">
<Image Width="24"
Height="24"
Margin="2"
Source="{TemplateBinding Icon}"
SnapsToDevicePixels="True"
RenderOptions.EdgeMode="Aliased" />
<Run BaselineAlignment="Center"
Text="{TemplateBinding Title}"
Foreground="{DynamicResource DefaultBackgroundBrush}"/>
</TextBlock>
<TextBlock DockPanel.Dock="Right" HorizontalAlignment="Right">
<!--This it the part I showed before -->
<StackPanel Width="38" Height="32">
<StackPanel.Style>
<Style TargetType="StackPanel">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Green"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
<Image
Width="38"
Height="32"
Margin="0"
Source="../Images/FrameControlIcons/38x32/close.png"/>
</StackPanel>
<!--/////////////////////-->
</TextBlock>
</DockPanel>
<DockPanel Grid.Column="1" Grid.Row="1" >
<ContentPresenter />
</DockPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
My co-worker recognized the problem. The Problem was, that my Image was covered by the CaptionHeight of the WindowChrome. When i set the CaptionHeigt to zero it works.
So i found a solution to make both work. The CaptionHeight (To drag the window around) and the mouse event on Element that are coverd by the CaptionHeight.
I had to set this property on the affected element:
shell:WindowChrome.IsHitTestVisibleInChrome="True"
I found this Solution here:
How can I add a button to the WPF caption bar while using custom window chrome?
I am creating a button style. Paste this into a window to see the idea:
<Style x:Key="SelectionButton3"
TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ClipToBounds="False">
<Grid.RowDefinitions>
<RowDefinition Height="75"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border x:Name="TheBorder"
BorderThickness="0,1.5,1.5,1.5"
CornerRadius="3"
Background="SteelBlue"
Height="35"
Grid.Column="1"
Grid.Row="0"
Margin="-31"
BorderBrush="DarkSlateBlue">
<Border.BitmapEffect>
<DropShadowBitmapEffect x:Name="BorderShadow"
ShadowDepth="0"/>
</Border.BitmapEffect>
</Border>
<Rectangle Fill="SteelBlue"
Stroke="DarkSlateBlue"
Grid.Row="0"
Grid.Column="0">
<Rectangle.LayoutTransform>
<RotateTransform Angle="-45" />
</Rectangle.LayoutTransform>
<Rectangle.BitmapEffect>
<DropShadowBitmapEffect ShadowDepth="5"/>
</Rectangle.BitmapEffect>
</Rectangle>
<ContentPresenter x:Name="ContentArea"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground"
Value="LightGray" />
<Setter Property="FontFamily"
Value="Segoe UI" />
</Style>
<Button Click="Button_Click"
Style="{StaticResource SelectionButton3}"
Width="185">
</Button>
What I would like to have happen is for the Borders drop shadow to appear when the mouse is over either the Border or the Rectangle. I know I need a trigger, but I'm not really sure where & how to do it.
Can someone point me in the right direction?
Thanks
<Style x:Key="SelectionButton3"
TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ClipToBounds="False">
<Grid.RowDefinitions>
<RowDefinition Height="75"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border x:Name="TheBorder"
BorderThickness="0,1.5,1.5,1.5"
CornerRadius="3"
Background="SteelBlue"
Height="35"
Grid.Column="1"
Grid.Row="0"
Margin="-31"
BorderBrush="DarkSlateBlue">
</Border>
<Rectangle Name="rect" Fill="SteelBlue"
Stroke="DarkSlateBlue"
Grid.Row="0"
Grid.Column="0">
<Rectangle.LayoutTransform>
<RotateTransform Angle="-45" />
</Rectangle.LayoutTransform>
</Rectangle>
<ContentPresenter x:Name="ContentArea"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="TheBorder" Property="BitmapEffect">
<Setter.Value>
<DropShadowBitmapEffect ShadowDepth="0" />
</Setter.Value>
</Setter>
<Setter TargetName="rect" Property="BitmapEffect">
<Setter.Value>
<DropShadowBitmapEffect ShadowDepth="5"/>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground"
Value="LightGray" />
<Setter Property="FontFamily"
Value="Segoe UI" />
</Style>
Note that unless you're using .NET 3.0 or 3.5 pre SP1, you should use Effect instead of BitmapEffect. The BitmapEffect property has been deprecated in 3.5 SP1
I have a WPF GridSplitter with a controltemplate being applied to add grips and buttons. The height is set to 20px. When I drag the splitter to resize my grid the preview is also 20px. I'd like to change the height of the preview while it's being dragged.
Is there a simple way to accomplish this?
<Style TargetType="{x:Type GridSplitter}" x:Key="AdvancedGridSplitter">
<Setter Property="Background" Value="{DynamicResource {x:Static themes:PropertyGridCommonDictionary.SummarySplitterBackgroundBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static themes:DockingCommonDictionary.DocumentTabBorderNormalBrushKey}}" />
<Setter Property="BorderThickness" Value="0,1" />
<Setter Property="Height" Value="20" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="ResizeBehavior" Value="PreviousAndNext" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="UIElement.SnapsToDevicePixels" Value="True" />
<Setter Property="UIElement.Focusable" Value="False" />
<Setter Property="ShowsPreview" Value="True" />
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Border x:Name="Root" BorderThickness="{TemplateBinding Border.BorderThickness}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" HorizontalAlignment="Center" Margin="2,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
<ribbon:Button Context="StatusBarItem" Cursor="Arrow" ImageSourceSmall="/Resources/Splitter/SplitterSwitch.png" ImageSourceSmallSize="11,11" Padding="2,0" />
</StackPanel>
<Grid Grid.Column="1" />
<StackPanel Grid.Column="2" HorizontalAlignment="Center" Orientation="Vertical" VerticalAlignment="Center" x:Name="Grip">
<Rectangle Fill="{DynamicResource {x:Static themes:PropertyGridCommonDictionary.BorderBrushKey}}" Height="1" Margin="1" Width="50">
<Rectangle.Effect>
<DropShadowEffect BlurRadius="1" Color="White" Direction="90" Opacity=".8" ShadowDepth="1" />
</Rectangle.Effect>
</Rectangle>
<Rectangle Fill="{DynamicResource {x:Static themes:PropertyGridCommonDictionary.BorderBrushKey}}" Height="1" Margin="1" Width="50">
<Rectangle.Effect>
<DropShadowEffect BlurRadius="1" Color="White" Direction="90" Opacity=".8" ShadowDepth="1" />
</Rectangle.Effect>
</Rectangle>
</StackPanel>
<Grid Grid.Column="3" />
<StackPanel Grid.Column="4" HorizontalAlignment="Center" Margin="0,0,2,0" Orientation="Horizontal" VerticalAlignment="Center">
<ribbon:Button Context="StatusBarItem" Cursor="Arrow" ImageSourceSmall="/Resources/Splitter/SplitterVertical.png" ImageSourceSmallSize="11,11" Padding="2,0" />
<ribbon:Button Context="StatusBarItem" Cursor="Arrow" ImageSourceSmall="/Resources/Splitter/SplitterHorizontal.png" ImageSourceSmallSize="11,11" IsChecked="True" Padding="2,0" />
<ribbon:Button Context="StatusBarItem" Cursor="Arrow" ImageSourceSmall="/Resources/Splitter/SplitterMinimize.png" ImageSourceSmallSize="11,11" Padding="2,0" />
</StackPanel>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="VerticalAlignment" Value="Stretch">
<Setter TargetName="Grip" Property="Orientation" Value="Vertical"/>
<Setter TargetName="Grip" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
You need to set the PreviewStyle on your GridSplitter:
PreviewStyle="{StaticResource AdvancedGridSplitterPreview}"
An appropriate style could be:
<Style TargetType="{x:Type Control}" x:Key="AdvancedGridSplitterPreview">
<Setter Property="Height" Value="4"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Rectangle>
<Rectangle.Fill>
<SolidColorBrush Opacity="0.4" Color="Black"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
See here in the MSDN for another description with example.
Hope this helps.