Finestra a scorrimento ed animazioni
bottaxxgp
bottaxxgp non è online. Ultima attività: 20/04/2009 11.08.37bottaxxgp
l'8 febbraio 2008 alle 13:29
13 messaggi dal 04 gennaio 2007
Ho fatto una finesta che normalmente sta nascosta nella parte sinistra dello schermo e presenta un bottone "always on top" quando si passa sul bottone questo sparisce e compare una fiestra.

Il tutto fatto con alcune animazioni.

Ora vorrei fare in modo che premendo un botton della finestra , questa rimanga sempre visibile.

Non riesco a trovare il modo per disabilitare le animazioni.

Qualche suggerimento?

Grazie mille.

Di seguito il codice.



Codice XAML in Window1.xaml

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
xmlnsbj="clr-namespacelidingWin;assembly=SlidingWin"
xmlns="http://schemas.microsoft.com/expression/blend/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="SlidingWin.Window1"
Title="" Height="300" Width="217" HorizontalAlignment="Left" VerticalAlignment="Top" AllowsTransparency="True" ResizeMode="NoResize" ShowInTaskbar="False" WindowStyle="None" Background="{x:Null}" Foreground="{x:Null}" Left="0" Topmost="True">
<Window.Resources>

<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle SnapsToDevicePixels="true" Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#F3F3F3" Offset="0"/>
<GradientStop Color="#EBEBEB" Offset="0.5"/>
<GradientStop Color="#DDDDDD" Offset="0.5"/>
<GradientStop Color="#CDCDCD" Offset="1"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
<Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {xtatic 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}">
<Microsoft_Windows_Themes:ButtonChrome SnapsToDevicePixels="true" x:Name="Chrome" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}">

<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True"/>
</Microsoft_Windows_Themes:ButtonChrome>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="true">
<Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="ButtonSlide" x:Name="DataTemplate">
<DockPanel Width="115">
<Label Width="74" Height="17" Content="{Binding}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Padding="0,0,0,0" />
<Label VerticalAlignment="Top" Width="29" Height="18" Content="Beta" Background="{x:Null}" FontWeight="Bold" Foreground="#FFFF0000" Padding="0,0,0,0" DockPanel.Dock="Top" HorizontalAlignment="Right" FontSize="11">

</Label>
</DockPanel>
</DataTemplate>
<Storyboard x:Key="ExpandWindow">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-160"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button" Storyboard.TargetProperty="(FrameworkElement.Height)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="32"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-160"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="grid" Storyboard.TargetProperty="(FrameworkElement.Margin)">
<SplineThicknessKeyFrame KeyTime="00:00:00" Value="0,0,0,0"/>
<SplineThicknessKeyFrame KeyTime="00:00:00.3000000" Value="0,0,0,0"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="CollapseWindow">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button" Storyboard.TargetProperty="(FrameworkElement.Height)">
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="32"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="-160"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="-160"/>
</DoubleAnimationUsingKeyFrames>
<ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="grid" Storyboard.TargetProperty="(FrameworkElement.Margin)">
<SplineThicknessKeyFrame KeyTime="00:00:00.3000000" Value="0,0,0,0"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="button">
<BeginStoryboard x:Name="ExpandWindow_BeginStoryboard" Storyboard="{StaticResource ExpandWindow}"/>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="grid">
<BeginStoryboard Storyboard="{StaticResource CollapseWindow}"/>
</EventTrigger>
</Window.Triggers>
<DockPanel HorizontalAlignment="Left" Width="Auto" x:Name="DockPanel">


<Grid Width="160" Height="264" Margin="-160,0,0,0" Visibility="Visible" x:Name="grid" MouseLeave="Grid_MouseLeave" RenderTransformOrigin="0.5,0.5" d:IsHidden="True">

<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Grid.RenderTransform>
<Grid.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Grid.LayoutTransform>

<DockPanel HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="DockPanel1" VerticalAlignment="Top" Width="{Binding Path=Width, ElementName=grid, Mode=Default}" Height="{Binding Path=Height, ElementName=DockPanel, Mode=Default}">
<StackPanel Width="{Binding Path=Width, ElementName=DockPanel, Mode=Default}" Height="{Binding Path=Height, ElementName=DockPanel, Mode=Default}">
<DockPanel x:Name="StackPanel" Width="{Binding Path=Width, ElementName=DockPanel1, Mode=Default}" Height="17" Background="{Binding Path=Fill, ElementName=rectangle, Mode=Default}">
<Label Width="{Binding ElementName=StackPanel, Mode=OneWay}" Height="22" Content="Label" Padding="1,1,1,1"/>
<Image HorizontalAlignment="Right" Width="14" Height="15" Source="unpin.png" MouseLeftButtonDown="Image_MouseLeftButtonDown" x:Name="imgPin"/>
</DockPanel>

<Rectangle Fill="#FFEA9191" Stretch="Fill" Stroke="#FF000000" x:Name="rectangle" Width="160" Height="264"/>

</StackPanel>
</DockPanel>

</Grid>
<Button HorizontalAlignment="Left" VerticalAlignment="Center" Width="121" Height="32" Content="Main" Style="{DynamicResource ButtonStyle1}" ContentTemplate="{DynamicResource ButtonSlide}" x:Name="button" MouseEnter="Button_MouseEnter" RenderTransformOrigin="0.5,0.5">
<Button.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="-90"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Button.LayoutTransform>

<Button.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFF3F3F3" Offset="0"/>
<GradientStop Color="#FFEBEBEB" Offset="0.5"/>
<GradientStop Color="#FFDDDDDD" Offset="0.5"/>
<GradientStop Color="{DynamicResource {xtatic SystemColors.GradientActiveCaptionColorKey}}" Offset="1"/>
</LinearGradientBrush>
</Button.Background>

<Button.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Button.RenderTransform>

</Button>
</DockPanel>
</Window>



Codice CS windows1.xaml.cs Reference PresentationFramework.Aero

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using IconImage = System.Drawing.Icon;

namespace SlidingWin
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{

public Window1()
{
InitializeComponent();

}

private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
BitmapImage bmp = new BitmapImage(new Uri("../../pin.png", UriKind.Relative));

imgPin.Source = bmp;



}

private void Button_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
((Storyboard)this.Resources["ExpandWindow"]).Begin(this);
e.Handled = true;
}

private void Grid_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
((Storyboard)this.Resources["CollapseWindow"]).Begin(this);
e.Handled = true;
}

}
}
RE: Finestra a scorrimento ed animazioni
Ricciolo
Ricciolo non è online. Ultima attività: 06/02/2010 11.33.28Ricciolo Top Poster
il 9 febbraio 2008 alle 00:30
Mi pare che sia tu a controllare le animazioni, giusto? Non puoi mica valutare una variabile per sapere se chiamare la begin o meno?
Io manterrei comunque un approccio di separazione codice/ui. Potresti infatti fare sulla tua finestra una DependencyProperty booleana con la quale fai partire un'animazione mediante Trigger. La cambi in true o false in funzione di IsMouseOver (quando cambia di valore) più una tua variabile per sapere se la finestra è in primo piano o meno.

Ciao

Il mio blog
Homepage

 

Torna al forum |   Feed RSS
ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.
COMMUNITY
ULTIMI MESSAGGI
UTENTI ONLINE
MEDIA
IN EVIDENZA
MISC
Powered by .db Forums "Caesar Reborn" v. 2010.2.8