WPF - How can I place a usercontrol over an AdornedElementPlaceholder? - wpf

alt text http://img42.imageshack.us/img42/4161/blinkthru.png
I'm trying to get the validation to not show through my custom modal dialog. I've tried setting the zindex of the dialog and and of the elements in this template. Any ideas?
This is coming from a validation template:
<ControlTemplate x:Key="ValidationTemplate">
<DockPanel>
<TextBlock Foreground="Red" FontSize="20" Panel.ZIndex="-10">!</TextBlock>
<Border Name="validationBorder" BorderBrush="Red" BorderThickness="2" Padding="1" CornerRadius="3" Panel.ZIndex="-10">
<Border.Resources>
<Storyboard x:Key="_blink">
<ColorAnimationUsingKeyFrames AutoReverse="True" BeginTime="00:00:00" Storyboard.TargetName="validationBorder" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" RepeatBehavior="Forever">
<SplineColorKeyFrame KeyTime="00:00:1" Value="#00FF0000"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</Border.Resources>
<Border.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource _blink}" />
</EventTrigger>
</Border.Triggers>
<AdornedElementPlaceholder/>
</Border>
</DockPanel>
</ControlTemplate>
The dialog:
<UserControl
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"
x:Class="GunMiser.Controls.PendingChangesConfirmationDialog"
Height="768" Width="1024" mc:Ignorable="d">
<Grid Background="White">
<Rectangle x:Name="MainRectangle" Margin="0,0,0,0" Style="{DynamicResource UserControlOverlayRectangleStyle}" Opacity="0.85"/>
<Border Margin="288,250,278,288" Background="#FF868686" BorderBrush="Black" BorderThickness="1">
<Border.Effect>
<DropShadowEffect Color="#FFB6B2B2"/>
</Border.Effect>
<TextBlock x:Name="textBlockMessage" Margin="7,29,7,97" TextWrapping="Wrap" d:LayoutOverrides="VerticalAlignment" TextAlignment="Center"/>
</Border>
<Button x:Name="OkButton" Click="OkButton_Click" Margin="313,0,0,328" VerticalAlignment="Bottom" Height="24" Content="Save Changes" Style="{DynamicResource GunMiserButtonStyle}" HorizontalAlignment="Left" Width="103"/>
<Button Click="CancelButton_Click" Margin="453.294,0,456,328" VerticalAlignment="Bottom" Height="24" Content="Cancel Changes" Style="{DynamicResource GunMiserButtonStyle}"/>
<Button Click="CancelActionButton_Click" Margin="0,0,304,328" VerticalAlignment="Bottom" Height="24" Content="Go Back" Style="{DynamicResource GunMiserButtonStyle}" HorizontalAlignment="Right" Width="114.706"/>
</Grid>
</UserControl>
And the overall window is:
<Window x:Class="GunMiser.Views.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.codeplex.com/CompositeWPF"
xmlns:controls="clr-namespace:GunMiser.Controls;assembly=GunMiser.Controls"
Title="Gun Miser"
Height="768" Width="1024">
<Canvas>
<controls:PendingChangesConfirmationDialog x:Name="PendingChangesConfirmationDialog" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Width="1008" Height="730" Visibility="Collapsed" Panel.ZIndex="100" />
<ContentControl x:Name="FilterRegion" cal:RegionManager.RegionName="FilterRegion" Width="326" Height="656" Canvas.Top="32" VerticalAlignment="Top" HorizontalAlignment="Left" />
<ContentControl Name="WorkspaceRegion" cal:RegionManager.RegionName="WorkspaceRegion" Width="678" Height="726" Canvas.Left="330" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<Button Click="GunsButton_Click" Width="75" Height="25" Content="Guns" Canvas.Top="3" Style="{DynamicResource GunMiserButtonStyle}"/>
<Button Click="OpticsButton_Click" Width="75" Height="25" Content="Optics" Canvas.Left="81" Canvas.Top="3" Style="{DynamicResource GunMiserButtonStyle}"/>
<Button Click="SettingsButton_Click" Width="56" Height="28" Content="Settings" Canvas.Left="944" Style="{DynamicResource GunMiserButtonStyle}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Button Click="AccessoriesButton_Click" Width="75" Height="25" Content="Accessories" Canvas.Left="239" Canvas.Top="3" Style="{DynamicResource GunMiserButtonStyle}"/>
<Button Click="AmmunitionButton_Click" Width="75" Height="25" Content="Ammunition" Canvas.Left="160" Canvas.Top="3" Style="{DynamicResource GunMiserButtonStyle}"/>
</Canvas>
</Window>

You problem is that the error template is shown in the adorner layer which in your case will be at the root window.
If you were to change your code to the following you wouldn't have a problem, because there would be a separate adorner layer created around the rest of you controls.
<Window x:Class="GunMiser.Views.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.codeplex.com/CompositeWPF"
xmlns:controls="clr-namespace:GunMiser.Controls;assembly=GunMiser.Controls"
Title="Gun Miser"
Height="768" Width="1024">
<Canvas>
<AdornerDecorator>
<Canvas>
<ContentControl x:Name="FilterRegion" cal:RegionManager.RegionName="FilterRegion" Width="326" Height="656" Canvas.Top="32" VerticalAlignment="Top" HorizontalAlignment="Left" />
<ContentControl Name="WorkspaceRegion" cal:RegionManager.RegionName="WorkspaceRegion" Width="678" Height="726" Canvas.Left="330" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<Button Click="GunsButton_Click" Width="75" Height="25" Content="Guns" Canvas.Top="3" Style="{DynamicResource GunMiserButtonStyle}"/>
<Button Click="OpticsButton_Click" Width="75" Height="25" Content="Optics" Canvas.Left="81" Canvas.Top="3" Style="{DynamicResource GunMiserButtonStyle}"/>
<Button Click="SettingsButton_Click" Width="56" Height="28" Content="Settings" Canvas.Left="944" Style="{DynamicResource GunMiserButtonStyle}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Button Click="AccessoriesButton_Click" Width="75" Height="25" Content="Accessories" Canvas.Left="239" Canvas.Top="3" Style="{DynamicResource GunMiserButtonStyle}"/>
<Button Click="AmmunitionButton_Click" Width="75" Height="25" Content="Ammunition" Canvas.Left="160" Canvas.Top="3" Style="{DynamicResource GunMiserButtonStyle}"/>
</Canvas>
</AdornerDecorator>
<controls:PendingChangesConfirmationDialog x:Name="PendingChangesConfirmationDialog" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Width="1008" Height="730" Visibility="Collapsed" Panel.ZIndex="100" />
</Canvas>

Alternatively, if you want to change just the style of the element (it's background, foreground, etc) and not it's whole ControlTemplate (which includes the adorner), you can set the Validation.ErrorTemplate so that it doesn't have a border, or exclamation point, then use a style trigger to change the style based on the property "Validation.HasError".
<Style TargetType="{x:Type TextBlock}" x:Key="TextBlockErrorStyle">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<!-- this gets rid of all adornment INCLUDING THE DEFAULT RED BORDER -->
<AdornedElementPlaceholder Name="controlWithError" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Background" Value="MistyRose"/>
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>

Related

WPF toggle visibility between 6 stack panels and hide all others when one is opened

I have six stack panel elements that are toggled all by a seperate toggle button which is what I need. However, when the user opens up one of the stack panels I would like to close all of the other ones and just show the one they have clicked on.
<Grid HorizontalAlignment="Left" Height="504" Margin="-1,1,0,0" VerticalAlignment="Top" Width="760">
<Grid.Resources>
<BooleanToVisibilityConverter x:Key="boolConverter" />
</Grid.Resources>
<StackPanel HorizontalAlignment="Left" Height="505" VerticalAlignment="Top" Width="124" Background="#FF45B8F9" Margin="1,-1,0,0"/>
<StackPanel HorizontalAlignment="Left" Height="505" VerticalAlignment="Top" Width="124" Background="#FFF95545" Margin="636,0,0,-1" Visibility="{Binding ElementName=button, Path=IsChecked, Converter={StaticResource boolConverter}}"/>
<StackPanel HorizontalAlignment="Left" Height="505" VerticalAlignment="Top" Width="124" Background="#FFF9F945" Margin="507,-1,0,0" Visibility="{Binding ElementName=button_Copy, Path=IsChecked, Converter={StaticResource boolConverter}}"/>
<StackPanel HorizontalAlignment="Left" Height="505" VerticalAlignment="Top" Width="124" Background="#FF76F945" Margin="378,-1,0,0" Visibility="{Binding ElementName=button1, Path=IsChecked, Converter={StaticResource boolConverter}}"/>
<ToggleButton x:Name="button" Content="Green" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="105" Click="button_Click"/>
<ToggleButton x:Name="button_Copy" Content="Yellow" HorizontalAlignment="Left" Margin="10,55,0,0" VerticalAlignment="Top" Width="105" Click="button_Click"/>
<ToggleButton x:Name="button1" Content="Red" HorizontalAlignment="Left" Margin="10,114,0,0" VerticalAlignment="Top" Width="105"/>
</Grid>
Make a RadioButton custom template to display like an Expander:
<Style TargetType="{x:Type RadioButton}">
<Setter Property="GroupName" Value="MyToggleButtonGroupName"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Expander IsExpanded="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsChecked}">
<ContentPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<RadioButton>
<StackPanel>...</StackPanel>
</RadioButton>
<RadioButton>
<StackPanel>...</StackPanel>
</RadioButton>
<RadioButton>
<StackPanel>...</StackPanel>
</RadioButton>

Mouse Jerky Over Controls In Multi Monitor Setup

We have a window which displays a message in the centre and with a semi transparent background as follows:
<Window x:Class="Dialogs.Touch.MessageWindow" Style="{DynamicResource DialogWindow}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:I.GUI.Controls.WPF"
Title="MessageWindow" WindowState="Maximized" AllowsTransparency="True" WindowStartupLocation="CenterScreen" PreviewKeyDown="Window_PreviewKeyDown">
<Window.Resources>
<ResourceDictionary x:Name="StyleDictionary">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/TouchStyle.xaml"/>
<ResourceDictionary Source="../Styles/DialogsStyle.xaml"/>
<ResourceDictionary Source="../../Styles/GUIStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Window.Background>
<SolidColorBrush x:Name="WindowBrush" Color="#88000000"/>
</Window.Background>
<ContentControl>
<Border Margin="20" Width="460" MaxHeight="1000" VerticalAlignment="Center" HorizontalAlignment="Center" Style="{DynamicResource WindowBorder}" >
<Grid Margin="0" >
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="{Binding ElementName=MessageTextBlock, Path=Height, Mode= OneWay}" />
<RowDefinition Height="90" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Name="IconColumn">
<ColumnDefinition.Style>
<Style TargetType="{x:Type ColumnDefinition}">
<Setter Property="Width" Value="58"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=IconImage, Path=Visibility}" Value="Collapsed" >
<Setter Property="Width" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ColumnDefinition.Style>
</ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="2" Style="{DynamicResource WindowHeaderBorder}">
<DockPanel>
<i:TouchButton DockPanel.Dock="Right" TouchButtonStyle="Quit" Content="X" Width="35" x:Name="Button1" />
<TextBlock VerticalAlignment="Center" Style="{DynamicResource LargeTextBlock}" Foreground="{DynamicResource LightTextColour1}" Text="Title" Name="TitleTextBlock"></TextBlock>
</DockPanel>
</Border>
<Image Name="IconImage" Width="48" Height="48" Grid.Row="1" Margin="5" VerticalAlignment="Top" HorizontalAlignment="Left" RenderOptions.BitmapScalingMode="Fant" Source="/SI.GUI;component/Images/warning.ico"></Image>
<TextBlock Margin="10,5,5,5" Grid.Row="1" Grid.Column="2" Style="{DynamicResource MediumTextBlock}" Text="Message" Name="MessageTextBlock" TextWrapping="Wrap"></TextBlock>
<StackPanel Grid.ColumnSpan="2" Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Bottom" FlowDirection="RightToLeft">
<i:TouchButton TouchButtonStyle="Negative" VerticalAlignment="Bottom" Content="Cancel" HorizontalAlignment="Right" Height="70" Width="150" x:Name="CancelButton"/>
<i:TouchButton TouchButtonStyle="Positive" VerticalAlignment="Bottom" Content="OK" HorizontalAlignment="Right" Height="70" Width="150" x:Name="OkButton"/>
</StackPanel>
</Grid>
</Border>
</ContentControl>
On one of our test machines when the mouse is placed over the message controls in the centre of the window which contain the message and buttons et (see border tags) the mouse cursor becomes very jerky.
It moves normally over the window background.
This only occurs when the system is in multi monitor mode. When only one monitor is used the cursor moves normally.
The system is running Windows XP.
Thanks

How can I add watermark text to a textbox in wpf?

Im working on a wpf application.How I can add watermark text to the textbox and passwordbox?
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Platforma Smart School 1.0" Height="580" Width="880"
Icon="/WpfApplication4;component/Images/capturennnnnn12_256px%20%282%291.ico">
<Grid>
<Grid.Background>
<ImageBrush ImageSource="/WpfApplication1;component/Images/
hp-colorful-books-hd-105609.jpg" />
</Grid.Background>
<Rectangle Height="334" HorizontalAlignment="Left" Margin="608,162,0,0"
Name="rectangle1" Stroke="#FFDBD8D8" VerticalAlignment="Top" Width="222"
Fill="#FFF0F0F0" />
<Button Height="34" HorizontalAlignment="Left" Margin="630,434,0,0"
Name="button1" VerticalAlignment="Top" Width="178" FontSize="13"
Foreground="#FF555555" />
<TextBox Height="34" HorizontalAlignment="Left" Margin="630,219,0,0"
Name="textBox1" VerticalAlignment="Top" Width="178" FontSize="14" Text=""
Foreground="#FF7C7A7A" />
<PasswordBox Height="32" HorizontalAlignment="Left" Margin="630,304,0,0"
Name="passwordBox1" VerticalAlignment="Top" Width="178" FontSize="14"
FontFamily="Segoe UI"/>
<Image Height="134" HorizontalAlignment="Left" Margin="606,12,0,0"
Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="224"
Source="/WpfApplication1;component/Images/Capture3.PNG" />
<Label Content=" Smart School" Height="31" HorizontalAlignment="Left"
Margin="251,498,0,0" Name="label1" VerticalAlignment="Top" Width="227" />
</Grid>
Take a look at this SO Question. The second answer of creating an Attached Property is what I would suggest.
There are also some extended WPF controls that can help: http://wpftoolkit.codeplex.com/wikipage?title=WatermarkTextBox
Edit: Added Extended WPF Toolkit link.
Or you could try this code
<Grid>
<Grid.Resources>
<VisualBrush x:Key="LoginHint" Stretch="None" AlignmentX="Left" AlignmentY="Top" >
<VisualBrush.Transform>
<TranslateTransform X="5" Y="7" />
</VisualBrush.Transform>
<VisualBrush.Visual>
<Grid HorizontalAlignment="Left">
<TextBlock FontFamily="SEGOEWP" FontSize="10" FontWeight="Normal"
HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="Gray" FontStyle="Italic" Opacity="1" Text="Enter Username"/>
</Grid>
</VisualBrush.Visual>
</VisualBrush>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label x:Name="lblUserName" Content="User Name" Grid.Column="0" VerticalAlignment="Top" Margin="5"/>
<TextBox x:Name="waterMarkTextBox" Width="100" Height="25" Grid.Column="1"
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="Transparent"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=waterMarkTextBox,Path=Text}" Value="" >
<Setter Property="Background" Value="{StaticResource LoginHint}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</Grid>
MahApps.Metro has a built-in watermark control and it's fairly straightforward to use. It does work with a PasswordBox.
<AdornerDecorator>
<PasswordBox Name="password"
Width="200"
HorizontalAlignment="Right">
<Controls:TextBoxHelper.Watermark>Password</Controls:TextBoxHelper.Watermark>
</PasswordBox>
</AdornerDecorator>

Local WPF C# Programming

i have a project on C# WPF, im just following the instruction and copying and pasting the code from the instruction. Im on the last part but unfortunately i received error in this part:
<local:SearchPanel Grid.Column="1" Grid.Row="1"
Visibility="{Binding ElementName=MyMovieDatabaseWindow, Path=IsSearchPaneVisible, Converter={StaticResource VisibilityConverter}}"/>
The errors are:
Error 1 ''local' is an undeclared prefix. Line 138, position 10.' XML is not valid. C:\Documents and Settings\xxxxx\Desktop\WPF Training Lab 1\WPF Training Lab 1\WPF Training Lab 1\MainWindow.xaml 138 10 WPF Training Lab 1
Error 2 The type 'local:SearchPanel' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. C:\Documents and Settings\xxxx\Desktop\WPF Training Lab 1\WPF Training Lab 1\WPF Training Lab 1\MainWindow.xaml 138 10 WPF Training Lab 1
Here's the FULL CODE:
MainWindow.xaml
<Window x:Class="WPF_Training_Lab.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="My Movie Database" Height="Auto" Width="Auto"
Icon="Res\Reel.png"
Background="{x:Static SystemColors.ControlDarkDarkBrush}"
x:Name="MyMovieDatabaseWindow" xmlns:local="clr-namespace:WPF_Training_Lab_1">
<Window.Resources>
<ControlTemplate x:Key="NavButtonTemplate" TargetType="{x:Type Button}">
<Label Content="{TemplateBinding Property=Content}">
<Label.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Label}">
<TextBlock> <TextBlock.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextDecorations" Value="Underline"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</TextBlock.Resources>
<ContentPresenter/>
</TextBlock>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="TextBlock.TextDecorations" Value="Underline" />
</Style>
</Label.Resources>
</Label>
</ControlTemplate>
<!-- Custom Commands -->
<RoutedUICommand x:Key="Command_NavigateToSearch" Text="Search"/>
<RoutedUICommand x:Key="Command_NavigateToReview" Text="Review"/>
<RoutedUICommand x:Key="Command_NavigateToMaintain" Text="Maintain"/>
<!-- Shared ToolTips-->
<ToolTip x:Key="TT_NavigateToSearch" Content="Navigate to the Search screen"/>
<ToolTip x:Key="TT_NavigateToReview" Content="Navigate to the Review screen"/>
<ToolTip x:Key="TT_NavigateToMaintain" Content="Navigate to the Maintain screen"/>
<!-- Images/Icons -->
<Image x:Key="Image_Cut" Source="Res\Cut.png" Height="12" Width="12"/>
<Image x:Key="Image_Copy" Source="Res\Copy.png" Height="12" Width="12"/>
<Image x:Key="Image_Paste" Source="Res\Paste.png" Height="12" Width="12"/>
</Window.Resources>
<Window.CommandBindings>
<CommandBinding x:Name="CommandBinding_Close" Command="Close" CanExecute="CommandBinding_Close_CanExecute" Executed="CommandBinding_Close_Executed"/>
<CommandBinding x:Name="CommandBinding_NavToSearch" Command="{StaticResource Command_NavigateToSearch}" CanExecute="CommandBinding_NavToSearch_CanExecute" Executed="CommandBinding_NavToSearch_Executed"/>
<CommandBinding x:Name="CommandBinding_NavToReview" Command="{StaticResource Command_NavigateToReview}" CanExecute="CommandBinding_NavToReview_CanExecute" Executed="CommandBinding_NavToReview_Executed"/>
<CommandBinding x:Name="CommandBinding_NavToMaintain" Command="{StaticResource Command_NavigateToMaintain}" CanExecute="CommandBinding_NavToMaintain_CanExecute" Executed="CommandBinding_NavToMaintain_Executed"/>
</Window.CommandBindings>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="115"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Menu Bar -->
<Menu Height="25" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0">
<MenuItem Header="_File">
<MenuItem Command="{StaticResource Command_NavigateToSearch}" Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" ToolTip="{StaticResource TT_NavigateToSearch}" />
</MenuItem>
<MenuItem Header="_Edit">
<MenuItem Command="{StaticResource Command_NavigateToSearch}" Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" ToolTip="{StaticResource TT_NavigateToSearch}"/>
<MenuItem Command="{StaticResource Command_NavigateToSearch}" Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" ToolTip="{StaticResource TT_NavigateToSearch}"/>
<MenuItem Command="{StaticResource Command_NavigateToSearch}" Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" ToolTip="{StaticResource TT_NavigateToSearch}"/>
</MenuItem>
<MenuItem Header="_Navigate">
<MenuItem Command="{StaticResource Command_NavigateToSearch}" Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" ToolTip="{StaticResource TT_NavigateToSearch}"/>
<MenuItem Command="{StaticResource Command_NavigateToSearch}" Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" ToolTip="{StaticResource TT_NavigateToSearch}"/>
<MenuItem Command="{StaticResource Command_NavigateToSearch}" Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" ToolTip="{StaticResource TT_NavigateToSearch}"/>
</MenuItem>
</Menu>
<Border Background="AliceBlue" CornerRadius="5" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Stretch" Margin="4,4,2,4">
<StackPanel HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,0" Cursor="Arrow" Background="Transparent">
<Image Source="Res\search.png" Height="14" Width="14" Margin="0,0,5,0"/>
<Button Template="{StaticResource NavButtonTemplate}" HorizontalAlignment="Center" Command="{StaticResource Command_NavigateToSearch}"
Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"
ToolTip="{StaticResource TT_NavigateToSearch}"
/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,0" Background="Transparent" Cursor="Arrow">
<Image Source="Res\settings_32.png" Height="14" Width="14" Margin="0,0,5,0"/>
<Button Template="{StaticResource NavButtonTemplate}" HorizontalAlignment="Center" Command="{StaticResource Command_NavigateToReview}"
Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"
ToolTip="{StaticResource TT_NavigateToReview}" />
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,0" Cursor="Hand" Background="Transparent">
<Image Source="Res\gear.png" Height="14" Width="14" Margin="0,0,5,0"/>
<Button Template="{StaticResource NavButtonTemplate}" HorizontalAlignment="Center" Command="{StaticResource Command_NavigateToMaintain}"
Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"
ToolTip="{StaticResource TT_NavigateToMaintain}" />
</StackPanel>
</StackPanel>
</Border>
<!-- User controls representing each of the panes the user can navigate to. -->
<local:SearchPanel Grid.Column="1" Grid.Row="1" Visibility="{Binding ElementName=MyMovieDatabaseWindow, Path=IsSearchPaneVisible, Converter={StaticResource VisibilityConverter}}"/>
</Grid>
</Window>
SearchPanel.xaml
<UserControl x:Class="WPF_Training_Lab_1.SearchPanel"
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"
mc:Ignorable="d"
xmlns:converters="clr-namespace:WPF_Training_Lab_2.Converters"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<RoutedUICommand x:Key="Command_Search" Text="Search"/>
<BooleanToVisibilityConverter x:Key="boolToVisibilityConverter"/>
<converters:NotBooleanToVisibilityConverter x:Key="notTheBoolConverter"/>
<converters:ThumbnailConverter x:Key="thumbnailConverter"/>
<converters:TextConverter x:Key="textConverter" />
<converters:TmdbImageConverter x:Key="tmdbImageConverter" />
<converters:CastMemberConverter x:Key="castMemberConverter"/>
<!-- Template defining the appearance of each item in the results listbox -->
<DataTemplate x:Key="SearchResultTemplate">
<DataTemplate.Resources>
<ToolTip x:Key="tooltip">
<ToolTip.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Click to see details for the movie "/>
<TextBlock Text="{Binding DbMovie.Name}"/>
</StackPanel>
</ToolTip.Content>
</ToolTip>
</DataTemplate.Resources>
<Border CornerRadius="5" Background="LightSteelBlue" BorderBrush="SteelBlue" BorderThickness="1" Margin="2,2,5,2"
MinWidth="285" ToolTip="{StaticResource tooltip}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.RowSpan="2" Margin="3" VerticalAlignment="Top" Width="92">
<Image.Source>
<BitmapImage UriSource="{Binding DbMovie.Images, Converter={StaticResource thumbnailConverter}, ConverterParameter='poster'}"
DecodePixelWidth="92"/>
</Image.Source>
</Image>
<TextBlock Margin="3" Grid.Column="1" Grid.Row="0" Text="{Binding DbMovie.Name}" FontWeight="Bold" TextWrapping="Wrap" />
<TextBlock Margin="5,3,3,3" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" Text="{Binding DbMovie.Overview, Converter={StaticResource textConverter}}" VerticalAlignment="Top" />
</Grid>
</Border>
</DataTemplate>
</UserControl.Resources>
<UserControl.CommandBindings>
<CommandBinding x:Name="CommandBinding_Search" Command="{StaticResource Command_Search}" CanExecute="CommandBinding_SearchCanExecute"
Executed="CommandBinding_SearchExecuted"/>
</UserControl.CommandBindings>
<Grid>
<!-- Search pane at top -->
<Border x:Name="SearchPane" HorizontalAlignment="Stretch" Margin="2,4,4,4">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" CornerRadius="5" Background="AliceBlue" Padding="5">
<Grid>
<Image Source="Res\Search.png" Height="48" Width="48" HorizontalAlignment="Left"/>
<StackPanel Margin="0,0,0,5" HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal" Margin="5">
<Label Content="Title: " FontWeight="Bold"/>
<TextBox x:Name="txtTitleSearch" Width="150" KeyUp="txtTitleSearch_KeyUp" ToolTip="Enter a movie title to search for" />
<Label Content="Year: " FontWeight="Bold" Margin="15,0,0,0"/>
<TextBox x:Name="txtYearFilter" Width="50" KeyUp="txtTitleSearch_KeyUp" ToolTip="Enter a year to narrow search results"/>
</StackPanel>
<Button x:Name="btnSearch" Content="Search" Margin="0,10,0,0" Width="75" Command="{StaticResource Command_Search}"
ToolTip="Click to perform the search"/>
</StackPanel>
<Image Source="Res\Search.png" Height="48" Width="48" HorizontalAlignment="Right"/>
</Grid>
</Border>
</Grid>
</Border>
<Border Grid.Row="2" CornerRadius="5" Background="AliceBlue" Padding="3">
<Grid VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" MinWidth="300"/>
<ColumnDefinition Width="3"/>
<ColumnDefinition Width="0.7*"/>
</Grid.ColumnDefinitions>
<Border CornerRadius="5" BorderBrush="LightSteelBlue" BorderThickness="1" Margin="0,0,3,0" Grid.Column="0"
Visibility="{Binding HasSearchResults, Converter={StaticResource boolToVisibilityConverter}}">
<ListBox ItemsSource="{Binding SearchResults}" ItemTemplate="{StaticResource SearchResultTemplate}" Grid.Column="0" Margin="-5" MinHeight="250" MinWidth="250" Width="Auto" Background="Transparent" x:Name="lstSearchResults" Padding="5"
BorderBrush="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Stretch"/>
</Border>
<Border CornerRadius="5" BorderBrush="LightSteelBlue" BorderThickness="1" Margin="0,0,3,0" Grid.Column="0"
Visibility="{Binding HasSearchResults, Converter={StaticResource notTheBoolConverter}}">
<Label VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold" FontSize="16">No Results</Label>
</Border>
<GridSplitter Grid.Column="1" Grid.Row="2" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="LightSteelBlue" />
</Grid>
</Border>
</Grid>
</UserControl>
How can i fix it? Thanks!
You are missing an "xmlns:local" attribute at the top of your XAML file. This should look something like:
xmlns:local="clr-namespace:YourAppNamespace"
Where YourAppNamespace is the namespace that contains the SearchPanel class.

Containing Story Board Animations in a Custom WPF Window

Okay, so here is my problem. I have a custom window with a custom shadow, as well as two translation transform animations. The end results is somewhat like the Window 8 Metro Screen. I.E. A Window in which there are several full window user controls that slide from Left to Right and vice versa. Now the problem is that I do not know how to contain the animations so that the they do not draw over the custom window shadow that I have.
Here is a screenshot of the problem:
And here is the window after the transition:
Here is the XAML for my window:
<Window x:Name="PrimaryWindow"
x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Metro_Test"
Title="MainWindow"
Height="800"
Width="1280"
IsTabStop="False"
AllowsTransparency="True"
Background="Transparent"
BorderBrush="#FF3F3F3F"
SnapsToDevicePixels="True"
TextOptions.TextFormattingMode="Display"
TextOptions.TextRenderingMode="ClearType"
WindowStyle="None"
WindowStartupLocation="CenterScreen" AllowDrop="True" ResizeMode="CanResizeWithGrip">
<Window.Resources>
<local:ValueConverter x:Key="NegativeConverter"/>
<Style x:Key="NoChromeButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="Chrome" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
<Setter Property="Opacity" TargetName="Chrome" Value="0.5"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Image x:Key="WhiteClose" Source="Images\White\Close.png" Height="24" Width="24"/>
<Image x:Key="WhiteAdd" Source="Images\White\Add.png" Height="24" Width="24"/>
<Image x:Key="WhiteMinus" Source="Images\White\Minus.png" Height="24" Width="24"/>
<Image x:Key="GrayClose" Source="Images\Gray\Close.png" Height="24" Width="24"/>
<Image x:Key="GrayAdd" Source="Images\Gray\Add.png" Height="24" Width="24"/>
<Image x:Key="GrayMinus" Source="Images\Gray\Minus.png" Height="24" Width="24"/>
<XmlDataProvider x:Key="PageViews">
<x:XData>
<Views xmlns="">
<View Title="View1">
<Page Source="MainPage.xaml"/>
</View>
<View Title="View2">
<Page Source="AddReferencePage.xaml"/>
</View>
<View Title="View3">
<Page Source="ReferenceManagementPage.xaml"/>
</View>
</Views>
</x:XData>
</XmlDataProvider>
<Storyboard x:Key="SlideLeftToRight"
TargetProperty="RenderTransform.(TranslateTransform.X)"
AccelerationRatio=".5"
DecelerationRatio=".5">
<DoubleAnimation Storyboard.TargetName="PageViewer" Duration="0:0:0.8" From="{Binding Width, ElementName=PrimaryWindow}" To="0"/>
<DoubleAnimation Storyboard.TargetName="BorderVisual" Duration="0:0:0.8" From="0" To="{Binding Width, ElementName=PrimaryWindow, Converter={StaticResource NegativeConverter}}"/>
</Storyboard>
<Storyboard x:Key="SlideRightToLeft"
TargetProperty="RenderTransform.(TranslateTransform.X)"
AccelerationRatio=".5"
DecelerationRatio=".5">
<DoubleAnimation Storyboard.TargetName="PageViewer" Duration="0:0:0.8" From="{Binding Width, ElementName=PrimaryWindow, Converter={StaticResource NegativeConverter}}" To="0"/>
<DoubleAnimation Storyboard.TargetName="BorderVisual" Duration="0:0:0.8" From="0" To="{Binding Width, ElementName=PrimaryWindow}"/>
</Storyboard>
<VisualBrush x:Key="VisualBrush1" Visual="{Binding ElementName=PageViewer}"/>
</Window.Resources>
<Border
x:Name="m_edgeBorder"
Margin="14"
Background="White">
<Border.Effect>
<DropShadowEffect
Opacity="0.999"
BlurRadius="14"
ShadowDepth="0"/>
</Border.Effect>
<Grid x:Name="MainGrid">
<Rectangle
x:Name="TitleBar"
Height="28"
Fill="Blue"
VerticalAlignment="Top"
AllowDrop="False"
PreviewMouseLeftButtonDown="FormMouseDown"
PreviewMouseMove="FormMouseMove"/>
<Button x:Name="CloseButton" Style="{DynamicResource NoChromeButton}" Click="HandleCloseClick" MouseEnter="HandleMouseEnter" MouseLeave="HandleMouseLeave" ClickMode="Release" HorizontalAlignment="Right" Margin="500,2,2,0" VerticalAlignment="Top" Width="24" Height="24">
<DynamicResource ResourceKey="GrayClose"/>
</Button>
<Button x:Name="MaximiseButton" Style="{DynamicResource NoChromeButton}" Click="HandleMaximiseClick" MouseEnter="HandleMouseEnter" MouseLeave="HandleMouseLeave" ClickMode="Release" HorizontalAlignment="Right" Margin="500,2,28,0" VerticalAlignment="Top" Width="24" Height="24">
<DynamicResource ResourceKey="GrayAdd"/>
</Button>
<Button x:Name="MinimiseButton" Style="{DynamicResource NoChromeButton}" Click="HandleMinimiseClick" MouseEnter="HandleMouseEnter" MouseLeave="HandleMouseLeave" ClickMode="Release" HorizontalAlignment="Right" Margin="500,2,54,0" VerticalAlignment="Top" Width="24" Height="24">
<DynamicResource ResourceKey="GrayMinus"/>
</Button>
<TextBlock Text="Metro Form" FontSize="18" FontFamily="Segoe Light" Margin="0,5" HorizontalAlignment="Center" Foreground="White"/>
<StackPanel>
<StackPanel Orientation="Vertical" Margin="0,28,0,0">
<ListBox x:Name="ViewList" Height="20" Width="300" SelectedIndex="0"
ItemsSource="{Binding Source={StaticResource PageViews}, XPath=Views/View}"
DisplayMemberPath="#Title"
SelectionChanged="ChangedSlideSelection">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</StackPanel>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Border x:Name="BorderVisual" HorizontalAlignment="Stretch">
<Rectangle x:Name="RectangleVisual"/>
<Border.RenderTransform>
<TranslateTransform/>
</Border.RenderTransform>
</Border>
<ItemsControl x:Name="PageViewer" DataContext="{Binding Path=SelectedItem, ElementName=ViewList}"
ItemsSource="{Binding XPath=Page}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Frame x:Name="frame" Source="{Binding XPath=#Source}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.RenderTransform>
<TranslateTransform/>
</ItemsControl.RenderTransform>
</ItemsControl>
</Grid>
</StackPanel>
</Grid>
</Border>
</Window>
Thank you!
Put a Border or a Grid or some other container as the container of the whole thing (right below the Window before any other element), with the needed Margin, and in your animations reference this element, instead of the Window.
Edit:
Should be something like:
<Window>
<Grid x:Name="MainGrid" Margin="10,0,10,0"> <!-- Or add more margin if needed -->
....
<DoubleAnimation From="0" To="{Binding ActualWidth, ElementName=MainGrid}"/>
....
</Grid
</Window>
Okay, I solved it! All I had to do was set the Grid's ClipToBounds property to true! Thanks to HighCore for putting me on the right track! If anyone experiences this problem and can't solve it, let me know!

Resources