I am building an application that looks like RoboZZle , but I have a problem:(the programming language in the answer is not important : C# or VB.NET)
I have three animations in the code behind which look like this:
Private Sub btngo_Click(sender As Object, e As RoutedEventArgs) Handles btngo.Click
go_stright()
go_stright()
go_stright()
go_stright()
End Sub
Private Sub go_stright()
Dim da As New DoubleAnimation()
Dim tt As New TranslateTransform()
da.From = offsety
offsety -= 50
da.To = offsety
da.Duration = New Duration(TimeSpan.FromSeconds(1))
tt.BeginAnimation(TranslateTransform.YProperty, da)
End Sub
This is the problem: when I click the "btngo" button, the last animation (4th go_stright) has animation effect. I need to wait until one animation is completed before the next one starts.
How can I do this?
Note: In roboZZle , the user with his algorithm moves sprite to destination and sprite movement isn't pre-defined.
i am a newbie in WPF.
Update: I have no Story Boards.
Update 2:My XAML:
<Page x:Class="Level1"
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"
d:DesignHeight="300" d:DesignWidth="300"
Title="Level1" Width="794" Height="535" Loaded="Page_Loaded_1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="735*"/>
<ColumnDefinition Width="69*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="65"/>
</Grid.RowDefinitions>
<Button x:Name="m1" Content="" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Width="54" Height="54" Margin="10,0,0,0">
<Button.Background>
<SolidColorBrush Color="White"/>
</Button.Background>
</Button>
<Button x:Name="m2" Content="" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Width="54" Height="54" Margin="69,1,0,0">
<Button.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}"/>
</Button.Background>
</Button>
<Button x:Name="m3" Content="" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Width="54" Height="54" Margin="128,1,0,0">
<Button.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}"/>
</Button.Background>
</Button>
<Button x:Name="m4" Content="" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Width="54" Height="54" Margin="187,1,0,0">
<Button.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}"/>
</Button.Background>
</Button>
<Button x:Name="m5" Content="" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Width="54" Height="54" Margin="246,0,0,0">
<Button.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}"/>
</Button.Background>
</Button>
<Button x:Name="m6" Content="" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Width="54" Height="54" Margin="305,0,0,0">
<Button.Background>
<SolidColorBrush Color="White"/>
</Button.Background>
</Button>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="215,100,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="215,149,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="215,199,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="215,249,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="215,299,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="264,299,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="314,299,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="364,299,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="413,299,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="413,100,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="413,149,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="413,199,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="413,249,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="264,100,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="314,100,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="50" Margin="364,100,0,0" VerticalAlignment="Top" Width="50">
<Rectangle.Stroke>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
</Rectangle.Stroke>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/l1khoone.png" Stretch="None"/>
</Rectangle.Fill>
</Rectangle>
<Ellipse x:Name="g1" HorizontalAlignment="Left" Height="25" Margin="228,313,0,0" VerticalAlignment="Top" Width="25">
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="#FF005DFF" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Button Content="" x:Name="btnup" HorizontalAlignment="Center" Width="54" Height="54" FlowDirection="RightToLeft" Margin="721,48,19,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Top" Grid.ColumnSpan="2">
<Button.Foreground>
<ImageBrush ImageSource="Images/up.jpg" Stretch="None">
<ImageBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterY="0.5" CenterX="0.5"/>
<SkewTransform CenterY="0.5" CenterX="0.5"/>
<RotateTransform CenterY="0.5" CenterX="0.5"/>
<TranslateTransform/>
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
</Button.Foreground>
<Button.Background>
<ImageBrush ImageSource="Images/up.jpg"/>
</Button.Background>
</Button>
<Button Content="" x:Name="btnleft" HorizontalAlignment="Center" Width="54" Height="54" Margin="721,107,19,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Top" Grid.ColumnSpan="2">
<Button.Foreground>
<ImageBrush ImageSource="Images/up.jpg" Stretch="None"/>
</Button.Foreground>
<Button.Background>
<ImageBrush ImageSource="Images/left.jpg"/>
</Button.Background>
</Button>
<Button Content="" x:Name="btnright" HorizontalAlignment="Center" Width="54" Height="54" Margin="721,166,19,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Top" Grid.ColumnSpan="2">
<Button.Foreground>
<ImageBrush ImageSource="Images/up.jpg" Stretch="None"/>
</Button.Foreground>
<Button.Background>
<ImageBrush ImageSource="Images/Right.jpg"/>
</Button.Background>
</Button>
<Button Content="" x:Name="btnf1" HorizontalAlignment="Center" Width="54" Height="54" Margin="721,225,19,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Top" Grid.ColumnSpan="2">
<Button.Foreground>
<ImageBrush ImageSource="Images/up.jpg" Stretch="None"/>
</Button.Foreground>
<Button.Background>
<ImageBrush ImageSource="Images/F1.jpg"/>
</Button.Background>
</Button>
<Button Content="" x:Name="btnf2" HorizontalAlignment="Center" Width="54" Height="54" Margin="721,284,19,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Top" Grid.ColumnSpan="2" IsEnabled="False">
<Button.Foreground>
<ImageBrush ImageSource="Images/up.jpg" Stretch="None"/>
</Button.Foreground>
<Button.Background>
<ImageBrush ImageSource="Images/F2.jpg"/>
</Button.Background>
</Button>
<Button Content="GO!" x:Name="btngo" HorizontalAlignment="Center" Width="54" Height="54" Margin="721,343,19,0" Background="Red" Foreground="White" FontFamily="Meiryo" FontSize="19" FontWeight="Bold" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Top" Grid.ColumnSpan="2"/>
<Button Content="Reset" x:Name="btnreset" HorizontalAlignment="Center" Width="54" Height="54" Margin="721,402,19,0" Foreground="White" FontFamily="Meiryo" FontSize="16" FontWeight="Bold" Background="Cyan" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Top" Grid.ColumnSpan="2"/>
<Ellipse x:Name="g2" HorizontalAlignment="Left" Height="25" Margin="427,313,0,0" VerticalAlignment="Top" Width="25">
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="#FF005DFF" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Ellipse x:Name="g3" HorizontalAlignment="Left" Height="25" Margin="427,112,0,0" VerticalAlignment="Top" Width="25">
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="#FF005DFF" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Image x:Name="sprite" Margin="215,100,461,320" Source="Images/downsprite.png" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
</Grid>
</Page>
You can add a completed event on the animation in which you will check how many steps you have to make and perform them if you're not there yet:
Private Sub btngo_Click(sender As Object, e As RoutedEventArgs) Handles btnGo.Click
PerformNextAction(actions(0))
End Sub
Private Sub go_stright()
Dim da As New DoubleAnimation(offsety, offsety - 50, New Duration(TimeSpan.FromSeconds(1)))
offsety -= 50
Dim tt As New TranslateTransform()
AddHandler da.Completed, AddressOf AnimationCompleted
tt.BeginAnimation(TranslateTransform.YProperty, da)
End Sub
Private Sub AnimationCompleted(sender As Object, e As EventArgs)
If actionCounter < 4 Then
actionCounter += 1
PerformNextAction(actions(actionCounter))
End If
End Sub
Private Sub PerformNextAction(ByVal action As Action)
Select Case action
Case MainWindow.Action.GoStraight
go_stright()
Case MainWindow.Action.RotateLeft
rotate_left()
Case MainWindow.Action.RotateRight
rotate_right()
End Select
End Sub
Don't forget this one too:
Private goStraightCounter As Integer
This one will keep track of your progress (how many times you need to keep calling the method).
Edit
To answer your comment, you could make an enum like this:
Public Enum Action
GoStraight
RotateRight
RotateLeft
End Enum
In the application you linked, the user has to make a list of action, so you could make that list a list of action (see enum). Then, instead of calling "go_stright", you just look at the next entry in the action list and call the method that goes for that action.
Edit 2:
To go deeper on actions, make a list of actions:
Public actions As ObservableCollection(Of Action)
So if the user has 5 actions he picked, you would have 5 enumactions in your list. So the list might look like this for example: GoStraight, RotateLeft, GoStraight, RotateLeft, GoStraight. In the animationcompleted event, instead of just calling the go_straight, you could implement a select case that checks which method you have to call (see updated code above). I just guessed how your go left and go right methods are called, so you might have to change those names.
Register an new EventHandler for the Completed Event in C#:
public MainWindow()
{
InitializeComponent();
System.Windows.Media.Animation.DoubleAnimation ani = new System.Windows.Media.Animation.DoubleAnimation();
ani.Completed += new EventHandler(ani_Completed);
}
void ani_Completed(object sender, EventArgs e)
{
throw new NotImplementedException();
}
I had the same problem.. Wire up a completed event and a property, then use a method that clears the dispatcher thread before returning..
// at the end of animation routine
progressTransition.Completed += new EventHandler(progressFlyOut_Completed);
progressTransition.Begin(ControlElement);
// allow animation to complete
WaitForCompletion(seconds * 2);
// completion event
private static void progressFlyOut_Completed(object sender, EventArgs e)
{
AnimationCompleted = true;
}
// wait routine
private static void WaitForCompletion(double TimeOut)
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
while (AnimationCompleted == false)
{
if (stopwatch.Elapsed.TotalSeconds > TimeOut)
break;
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => { })).Wait();
}
AnimationCompleted = false;
}
Related
<Path Data="M0.5,0 L0.5,1 M0,0.5 L1,0.5"
StrokeThickness="4"
Stretch="Fill"
Stroke="Blue" />
This will draw a plus sign on a button if the button is the only thing in window,
but how can one map the path to this button?
<ControlTemplate x:Key="BT_SIGN" TargetType="{x:Type Button}">
<Grid Cursor="None" Margin="0,0,1.333,0">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF1E8CF3" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
</Grid>
</ControlTemplate>
<Button
Grid.Column="3"
HorizontalAlignment="Left"
Height="44.8"
Width="75.2"
Margin="22.32,24.6,0,0"
VerticalAlignment="Top"
Template="{DynamicResource BT_SIGN}">
</Button>
Try this, i.e. add a <ContentPresenter /> to the template and set the Content property to your Path:
<ControlTemplate x:Key="BT_SIGN" TargetType="{x:Type Button}">
<Grid Cursor="None" Margin="0,0,1.333,0">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF1E8CF3" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<ContentPresenter />
</Grid>
</ControlTemplate>
<Button
Grid.Column="3"
HorizontalAlignment="Left"
Height="44.8"
Width="75.2"
Margin="22.32,24.6,0,0"
VerticalAlignment="Top"
Template="{DynamicResource BT_SIGN}">
<Path Data="M0.5,0 L0.5,1 M0,0.5 L1,0.5"
StrokeThickness="4"
Stretch="Fill"
Stroke="Blue" />
</Button>
Just set the Path of that specific button inside the button markup.
<Button
Grid.Column="3"
HorizontalAlignment="Left"
Height="44.8"
Width="75.2"
Margin="22.32,24.6,0,0"
VerticalAlignment="Top"
Template="{DynamicResource BT_SIGN}">
<Path Data="M0.5,0 L0.5,1 M0,0.5 L1,0.5"
StrokeThickness="4"
Stretch="Fill"
Stroke="Blue" />
</Button>
I am trying to set an image as a background of my window. I want to apply a gradient opacity mask over the window, and have the image tiled. So far, I can get either or, but not both. Here's my lame attempt at this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height = "40*" />
<RowDefinition Height="133*"/>
</Grid.RowDefinitions>
<Grid.Resources>
<Image x:Key="myImage" Source="/GrimshawRibbon;component/Resources/GeometricBackground.png">
<Image.OpacityMask>
<LinearGradientBrush EndPoint = "0.5,0" StartPoint="0.5,1">
<GradientStop Color = "#00000000" Offset="0.6"/>
<GradientStop Color = "#FF000000" Offset="1"/>
</LinearGradientBrush>
</Image.OpacityMask>
</Image>
<ImageBrush x:Key="imageBrush" ImageSource="/GrimshawRibbon;component/Resources/GeometricBackground.png" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,800,800"/>
<VisualBrush x:Key="myBrush" Visual="{StaticResource myImage}" Stretch="None" TileMode="Tile"/>
</Grid.Resources>
<DockPanel LastChildFill = "False" Grid.RowSpan="2" Background="{StaticResource imageBrush}"/>
<ContentControl x:Name="MainContentControl" Content="{Binding CurrentPageViewModel}" Margin="10" Grid.Row="1"/>
<Button x:Name="btnCancel" Content="Close" Margin="0,0,90,10" HorizontalAlignment="Right" Width="75" Height="36" VerticalAlignment="Bottom" Command="{Binding CloseWindowCommand, Mode=OneWay}" CommandParameter="{Binding ElementName=win}" Grid.Row="1"/>
<Button x:Name="button" Content="?" Margin="0,0,170,10" Height="36" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="36" Command="{Binding NavigateToHelpCommand, Mode=OneWay}" Grid.Row="1"/>
<Label x:Name="label" Content="Some label" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" FontWeight="Bold" FontSize="14"/>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="10,39,0,0" TextWrapping="Wrap" Text="Some tool description that is not too long. It would be good to keep it under two sentences." VerticalAlignment="Top" Height="36" Width="272"/>
</Grid>
You may assign the DockPanel's OpacityMask:
<DockPanel Grid.RowSpan="2" Background="{StaticResource imageBrush}">
<DockPanel.OpacityMask>
<LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
<GradientStop Color="#00000000" Offset="0.6"/>
<GradientStop Color="#FF000000" Offset="1"/>
</LinearGradientBrush>
</DockPanel.OpacityMask>
</DockPanel>
Or probably just use a Rectangle for the background image:
<Rectangle Grid.RowSpan="2" Fill="{StaticResource imageBrush}">
<Rectangle.OpacityMask>
<LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
<GradientStop Color="#00000000" Offset="0.6"/>
<GradientStop Color="#FF000000" Offset="1"/>
</LinearGradientBrush>
</Rectangle.OpacityMask>
</Rectangle>
In reference to this question that was answered yesterday:
How to capture tap event on specific button in user control from main form
I am now facing the issue where I have a "dashboard" usercontrol, so now I have to add multiple tap events to the same user control.
What's happening though is it seems that only the first tap event is firing.
Help?
(page 03 is the one in question)
mainform:
public MainPage() {
InitializeComponent();
Page02.CloseButtonTapped += Page02_CloseButtonTapped;
Page03.CloseButtonTapped += Page03_CloseButtonTapped;
Page11.CloseButtonTapped += Page11_CloseButtonTapped;
Page03.CommandControlTapped += Page03_CommandControlTapped;
}
page03:
public delegate void CloseButtonTappedHandler(object sender, TappedRoutedEventArgs e);
public delegate void CommandControlTappedHandler(object sender, TappedRoutedEventArgs e);
public sealed partial class Page03 : UserControl {
public event CloseButtonTappedHandler CloseButtonTapped;
public event CommandControlTappedHandler CommandControlTapped;
public Page03() {
this.InitializeComponent();
this.imgCloseButton.Tapped += new TappedEventHandler(this.imgCloseButton_Tapped);
this.imgTraining.Tapped += new TappedEventHandler(this.imgTraining_Tapped);
this.imgCommandControl.Tapped += new TappedEventHandler(this.imgCommandControl_Tapped);
}
private void imgCloseButton_Tapped(object sender, TappedRoutedEventArgs e) {
if (CloseButtonTapped != null) {
CloseButtonTapped(sender, e);
}
}
private void imgCommandControl_Tapped(object sender, TappedRoutedEventArgs e) {
if (CommandControlTapped != null) {
CommandControlTapped(sender, e);
}
}
private void imgTraining_Tapped(object sender, TappedRoutedEventArgs e) {
if (CommandControlTapped != null) {
CommandControlTapped(sender, e);
}
}
}
Page03 User Control XAML: (there's a bunch of layout stuff in there, line shapes, etc)
<UserControl
x:Class="Raytheon.Page03"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Raytheon"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="918"
d:DesignWidth="1818" Background="Gray">
<Grid>
<Rectangle HorizontalAlignment="Left" Height="48" Margin="625,416,0,0" StrokeThickness="3" VerticalAlignment="Top" Width="557" Opacity="0.5">
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="1457.34" Margin="896.467,-53.724,0,-485.616" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
<Rectangle.RenderTransform>
<CompositeTransform Rotation="-90" ScaleX="-1"/>
</Rectangle.RenderTransform>
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="1457.345" Margin="896.467,-523.224,0,-16.121" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
<Rectangle.RenderTransform>
<CompositeTransform Rotation="-90" ScaleX="-1"/>
</Rectangle.RenderTransform>
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="478" Margin="396,201,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3">
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Image x:Name="image" HorizontalAlignment="Left" Height="72" Margin="665,404,0,0" VerticalAlignment="Top" Width="467" Source="Assets/1920x1080_TailoredSolutions.png"/>
<Image x:Name="image1" HorizontalAlignment="Left" Height="69" Margin="126,296,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_Training.png"/>
<Rectangle HorizontalAlignment="Left" Height="228" Margin="506.55,325.193,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
<Rectangle.RenderTransform>
<CompositeTransform Rotation="-90" ScaleX="-1"/>
</Rectangle.RenderTransform>
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="478" Margin="1402,201,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3">
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="228" Margin="1291.55,325.193,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
<Rectangle.RenderTransform>
<CompositeTransform Rotation="-90" ScaleX="-1"/>
</Rectangle.RenderTransform>
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="214" Margin="1076,201,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3">
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="214" Margin="1076,466,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3">
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="214" Margin="731,201,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3">
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Height="214" Margin="731,466,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3">
<Rectangle.Fill>
<SolidColorBrush Color="White" Opacity="0.85"/>
</Rectangle.Fill>
</Rectangle>
<Image x:Name="imgCloseButton" HorizontalAlignment="Left" Height="111" Margin="1669,30,0,0" VerticalAlignment="Top" Width="111" Source="Assets/CloseButton.png" Tapped="imgCloseButton_Tapped"/>
<Image x:Name="txtSustainment" HorizontalAlignment="Left" Height="69" Margin="439,296,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_Sustainment.png"/>
<Image x:Name="txtCommunicaton" HorizontalAlignment="Left" Height="69" Margin="1134,296,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_Communications.png"/>
<Image x:Name="txtFixedSensors" HorizontalAlignment="Left" Height="69" Margin="1438,296,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_FixedSensors.png"/>
<Image x:Name="txtPhysicalSecurity" HorizontalAlignment="Left" Height="86" Margin="1438,775,0,0" VerticalAlignment="Top" Width="270" Source="Assets/1920x1080_Text_PhysicalSecurity.png"/>
<Image x:Name="txtPlatformUpgrades" HorizontalAlignment="Left" Height="88" Margin="1132,773,0,0" VerticalAlignment="Top" Width="279" Source="Assets/1920x1080_Text_PlatformUpgrades.png"/>
<Image x:Name="txtDataAnalytics" HorizontalAlignment="Left" Height="88" Margin="783,773,0,0" VerticalAlignment="Top" Width="279" Source="Assets/1920x1080_Text_DataAnalytics.png"/>
<Image x:Name="txtDistributedSensors" HorizontalAlignment="Left" Height="69" Margin="439,763,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_DistributedSensors.png"/>
<Image x:Name="txtMobileSensors" HorizontalAlignment="Left" Height="69" Margin="126,763,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_MobileSensors.png"/>
<Image x:Name="txtCommandControl" HorizontalAlignment="Left" Height="69" Margin="783,296,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_CommandControl.png"/>
<Image x:Name="imgTraining" HorizontalAlignment="Left" Height="224" Margin="128,94,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_Training.png" Tapped="imgTraining_Tapped"/>
<Image x:Name="imgSustainment" HorizontalAlignment="Left" Height="224" Margin="441,94,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_Sustainment.png"/>
<Image x:Name="imgCommunications" HorizontalAlignment="Left" Height="224" Margin="1136,94,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_Communications.png"/>
<Image x:Name="imgMobileSensors" HorizontalAlignment="Left" Height="224" Margin="128,561,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_MobileSensors.png"/>
<Image x:Name="imgDistributedSensors" HorizontalAlignment="Left" Height="224" Margin="441,561,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_DistributedSensors.png"/>
<Image x:Name="imgDataAnalytics" HorizontalAlignment="Left" Height="224" Margin="785,561,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_DataAnalytics.png"/>
<Image x:Name="imgPlatformUpgrades" HorizontalAlignment="Left" Height="224" Margin="1136,561,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_PlatformUpgrades.png"/>
<Image x:Name="imgFixedSensors" HorizontalAlignment="Left" Height="224" Margin="1440,94,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_FixedSensors.png"/>
<Image x:Name="imgPhysicalSecurity" HorizontalAlignment="Left" Height="224" Margin="1440,561,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_PhysicalSecurity.png"/>
<Image x:Name="imgCommandControl" HorizontalAlignment="Left" Height="224" Margin="785,94,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_CommandControl.png" Tapped="imgCommandControl_Tapped"/>
</Grid>
</UserControl>
You need to register for the events on Page03 individually in the MainPage and not create new handlers for them. See below
Page03.CloseButtonTapped += MethodToHandleEvent
Page03.Page11Tapped += MethodToHandleEvent
The lines calling AddHandler, are registering new handlers for the events and I think this is causing you some confusion. You may want to read up a bit more about events here: https://msdn.microsoft.com/en-us/library/ms742806(v=vs.100).aspx
I figured it out. It's because how I'm showing/hiding the user controls is via changing the opacity:
<local:Page01 Margin="53,156,8,10" x:Name="Page01" />
<local:Page02 Margin="53,156,8,30" x:Name="Page02" Opacity="0"/>
<local:Page11 Margin="53,156,8,30" x:Name="Page11" Opacity="0"/>
<local:Page03 Margin="53,156,8,30" x:Name="Page03" Opacity="0"/>
so I swapped the order of page 11 and page 3, and it started working. So now becomes the task of having to show/hide the user controls while retaining the storyboard animation, but not having them actually just "hidden" vs actually making them visible/collapsed.
I don't know how vague this may sound, so if you require more information, please let me know!
I've finished my program, and I've attempted to try running it on other machines, I have not used any installers to deploy this, I just have been using the debug/release programName.exe after compiling it.
My question is that is there reason why my program is running incredibly slow when it's not running on the system it was compiled on? the entire UI lags, as in it takes several sections just to switch to another tab, while running on its native computer, it runs perfectly smooth.
I've tried the publish wizard, so I don't think that'll help. I was wondering if it has to do with any the my xaml, the DLLs, or the program's dependencies? At the moment, I don't have any sort of pictures or resources that it's relying on.
Any advice on any changes that I can make to get this running more smoothly would be greatly appreciated.
Here's my mainWindow Xaml:
<Window
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:custom="clr-namespace:RemotePatch"
x:Class="RemotePatch.MainWindow"
mc:Ignorable="d"
Title="Remote Patch" Height="350" Width="525" AllowsTransparency="True" WindowStyle="None" ResizeMode="CanResizeWithGrip" Loaded="Window_Loaded_1" Closed="Window_Closed">
<Window.Effect>
<DropShadowEffect BlurRadius="0" ShadowDepth="0" Direction="0" Opacity="0"/>
</Window.Effect>
<Grid RenderTransformOrigin="0.497,0.518">
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition/>
<RowDefinition Height="317*"/>
</Grid.RowDefinitions>
<Grid.Background>
<RadialGradientBrush Center="0.5,0.6">
<GradientStop Color="#FF1A8BA2"/>
<GradientStop Color="#FF293855" Offset="1"/>
<GradientStop Color="#FF1799AE" Offset="0.043"/>
</RadialGradientBrush>
</Grid.Background>
<Rectangle Fill="#FFF4F4F5" Height="29" Stroke="Black" VerticalAlignment="Top" Opacity="0" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown"/>
<TabControl x:Name="tabControl" Margin="0,5,0,16" Grid.Row="2" >
<TabControl.Resources>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Border x:Name="Border" BorderThickness="1,1,1,0" BorderBrush="Gainsboro" CornerRadius="4,4,4,4" Margin="2,0">
<ContentPresenter x:Name="ContentSite"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
Margin="10,2"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="LightSkyBlue" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="Background" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabControl.Foreground>
<ImageBrush/>
</TabControl.Foreground>
<TabControl.BorderBrush>
<ImageBrush/>
</TabControl.BorderBrush>
<TabControl.Background>
<ImageBrush/>
</TabControl.Background>
<TabItem Header="General" Margin="0,7,0,-7">
<TabItem.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF040101" Offset="1"/>
</LinearGradientBrush>
</TabItem.Background>
<Grid>
<ListBox x:Name="listBox1" Margin="4,154,358,0" Foreground="White" Background="#FF14142E"/>
<TextBox x:Name="txtFile" Height="18" Margin="79,80,264,0" TextWrapping="Wrap" VerticalAlignment="Top" Background="#FF14142E" Foreground="White" MinWidth="56"/>
<TextBox x:Name="txtPSexec" Height="18" Margin="79,47,264,0" TextWrapping="Wrap" VerticalAlignment="Top" Background="#FF14142E" Foreground="White" MinWidth="56" />
<TextBox x:Name="txtGroups" HorizontalAlignment="Left" Height="18" Margin="79,119,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="65" Background="#FF14142E" Foreground="White"/>
<Button x:Name="buttonLoad" Content="Load File" Margin="4,78,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="56" Click="Load_Clicked">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="buttonSplit" Content="Split" Margin="4,117,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="56" Click="Split_Clicked">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="buttonValidate" Content="✔" Foreground="White" Height="15" VerticalAlignment="Top" HorizontalAlignment="Right" Width="15" Click="Validate_Clicked" FontSize="10.667" RenderTransformOrigin="0.062,0" Margin="0,154,358,0" FontWeight="Bold" >
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.413"/>
<GradientStop Color="#FF6C6C6C" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="buttonPsExec" Content="PsExec" Margin="4,46,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="58" Click="Psexec_Click">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="buttonLoginMain" Content="Login" Margin="452,6,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="58" Click="Login_Clicked">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
</Grid>
</TabItem>
<TabItem Header="Log" Margin="-3,7,3,-7">
<Grid>
<Grid.Background>
<ImageBrush/>
</Grid.Background>
<RichTextBox x:Name="richTextBox1" Margin="0,6,0,5" Background="Black" Foreground="White" TextChanged="richTextBox1_TextChanged" IsReadOnly="True">
<FlowDocument>
<Paragraph>
<Run Text="Remote Patch v2.0"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</Grid>
</TabItem>
<TabItem Header="Patch" Margin="-3,7,3,-7">
<Grid Margin="0,5,0.333,-5.333">
<Grid.Background>
<ImageBrush/>
</Grid.Background>
<Button x:Name="buttonLogin" Content="Login" Margin="0,10,1,0" Foreground="White" FontWeight="Bold" Grid.Row="2" Height="20" VerticalAlignment="Top" HorizontalAlignment="Right" Width="47" Click="Login_Clicked">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<GroupBox x:Name="groupBox" Header="Predefined Patches
" Margin="27,56,87,0" VerticalAlignment="Top" Height="55" Foreground="White">
<Button x:Name="buttonPredefined" Content="Run" Margin="9,-7,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="51" Click="buttonPredefined_Click">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
</GroupBox>
<ComboBox x:Name="comboBox" Margin="132,81,102,0" VerticalAlignment="Top" Background="#FF0F0F59" SelectionChanged="comboBox_SelectionChanged" Foreground="Black" />
<GroupBox x:Name="groupBox_Copy" Header="Batch File
" Margin="27,143,82,0" VerticalAlignment="Top" Height="55" Foreground="White">
<Button x:Name="buttonBatch" Content="Run" Margin="0,40,0,-43" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="51" Click="Batch_Clicked" Visibility="Hidden">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
</GroupBox>
<TextBox x:Name="txtBatchFile" Height="23" Margin="127,168,102,0" TextWrapping="Wrap" VerticalAlignment="Top" Background="#FF14142E" Foreground="White"/>
<Button x:Name="ButtonRunBatch" Content="Run" Margin="42,168,0,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="51" Click="loopBatch_Clicked">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="buttonAddFile" Content="+" Margin="0,168,47,0" Foreground="White" FontWeight="Bold" Height="20" VerticalAlignment="Top" Click="Add_Clicked" HorizontalAlignment="Right" Width="30">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Grid HorizontalAlignment="Left" Height="35" Margin="182,198,0,0" VerticalAlignment="Top" Width="106">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Height="40" Margin="25,5,-13,-10" VerticalAlignment="Top" Width="94">
<TextBox x:Name="numerical" TextWrapping="Wrap" Width="34" Margin="0,10,0,9.667" Background="#FF14142E" Foreground="White" TextChanged="textBox_TextChanged"/>
<Button x:Name="button1" Content="-" HorizontalAlignment="Left" VerticalAlignment="Top" Width="14" Height="19" Margin="0,10,0,0" Background="#FFFFEFEF" FontSize="10.667" FontWeight="Bold" Click="button1_Click"/>
<Button x:Name="button" Content="+" HorizontalAlignment="Left" VerticalAlignment="Top" Width="14" Height="19" Margin="0,10,0,0" FontSize="10.667" FontWeight="Bold" Click="addNumValue"/>
</StackPanel>
</Grid>
<Label x:Name="label2" Content="Groups" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="209,231,0,0" Foreground="White"/>
</Grid>
</TabItem>
</TabControl>
<Button x:Name="button2" Content="-" Margin="0,2,53,10" Foreground="White" FontWeight="Bold" HorizontalAlignment="Right" Width="21" Click="Minimize_Click">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button2_Copy" Margin="0,2,27,10" Foreground="White" HorizontalAlignment="Right" Width="21" Click="Maximize_Click">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
<Canvas>
<Rectangle Height="9" Width="9" Stroke="White" Canvas.Top="-2" Canvas.Left="-4"/>
<Rectangle Height="10" Width="10" Stroke="White" Canvas.Left="-2" Canvas.Top="-7" RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-0.715"/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
</Button>
<Button x:Name="button2_Copy1" Content="X" Margin="0,2,0,10" Foreground="White" FontWeight="Bold" HorizontalAlignment="Right" Width="22" Click="button2_Copy1_Click">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.27"/>
<GradientStop Color="#FF4F4F4F" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Label x:Name="label" Content="Remote Patch" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Width="108" Foreground="White" FontSize="16" IsHitTestVisible="False"/>
<Rectangle Grid.Row="2" Height="20" VerticalAlignment="Bottom" Fill="Transparent" Margin="-1,0,0,0"/>
<Label x:Name="label1" Content="Authenticated" HorizontalAlignment="Left" Grid.Row="2" Width="84" RenderTransformOrigin="0.5,0.5" Foreground="White" Height="23" VerticalAlignment="Bottom">
<Label.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleY="-0.718"/>
<RotateTransform/>
<TranslateTransform Y="-0.294"/>
</TransformGroup>
</Label.RenderTransform>
</Label>
<Ellipse x:Name="authColor" Fill="Red" HorizontalAlignment="Left" Margin="83,0,0,4" Grid.Row="2" Stroke="Black" Width="13" Height="13" VerticalAlignment="Bottom"/>
<Label x:Name="labelSettings" Content="Settings" Margin="0,-1,84,0" VerticalAlignment="Top" Foreground="#FF595555" FontWeight="Bold" HorizontalAlignment="Right" Width="56" MouseLeftButtonDown="labelSettings_MouseLeftButtonDown"/>
<Rectangle x:Name="rectangleNotification" Fill="#FFDDFF03" Grid.Row="2" Stroke="Black" Height="25" VerticalAlignment="Bottom" Opacity="0" Margin="0,0,1,0"/>
<Rectangle Height="2" Margin="30,31,30,0" Stroke="#FF444444" VerticalAlignment="Top" Grid.RowSpan="2" Opacity="0.5"/>
</Grid>
</Window>
You have a DropShadowEffect applied to your Window.
This is a problem because the DropShadowEffect uses all descendant objects to calculate the shape of the shadow. That means every single object contained in your Window is being inspected by this effect while rendering -- this takes a really long time.
Your shadow effect has 0 opacity anyway so you could just remove it.
Alternatively, you should apply the effect to a child of the Window, but make sure that child has no descendants.
The trick I use to apply the shadow to a window without destroying performance is to surround the contents of my window in a grid, place a border (or similar object) at the top of said grid (remember to assign a background to the border otherwise you won't get a shadow) and then apply the effect to the border instead of your window.
Before:
<Window x:Class="MyProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="400"
WindowStyle="None" AllowsTransparency="True" Background="Transparent">
<Window.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="0"/>
</Window.Effect>
<StackPanel Margin="8" Background="White">
<Button Margin="4">Test</Button>
<Button Margin="4">Test</Button>
<Button Margin="4">Test</Button>
</StackPanel>
</Window>
After:
<Window x:Class="MyProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="400"
WindowStyle="None" AllowsTransparency="True" Background="Transparent">
<Grid Margin="8">
<Border Background="White">
<Border.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="0"/>
</Border.Effect>
</Border>
<StackPanel>
<Button Margin="4">Test</Button>
<Button Margin="4">Test</Button>
<Button Margin="4">Test</Button>
</StackPanel>
</Grid>
</Window>
This provides the exact same appearance, but with better performance because:
The buttons are no longer involved in the calculation of the shadow
The border has no descendants, so the effect is only using the layout of the border in the calculation
General rule of thumb... Only apply the drop shadow effect to objects whose ancestors are intended to be affected by the effect.
I have a button with multiple contetnt. I want to change it's text when the button is clicked.
XAML:
<Button HorizontalAlignment="Left" Height="114" Margin="33,58,0,0" VerticalAlignment="Top" Width="224" Style="{StaticResource GlassButtonStyle}" FontSize="26.667" Click="Button_Click_1" Name="button1">
<StackPanel Orientation="Horizontal">
<Rectangle Height="69" Stroke="Black" Width="69">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.004,1.044" StartPoint="0.739,0.25">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter Content="Clicke me" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</Button>
C# code:
button1.Content = "Hello world";
This makes the rectangle disappear, though I want only to change the text. How can I do this?
You need to modify the Control Template of Button to show your rectangle all the time.
<Button HorizontalAlignment="Left" Height="114" Margin="33,58,0,0" VerticalAlignment="Top" Width="224" Style="{StaticResource GlassButtonStyle}" FontSize="26.667" Click="Button_Click_1" Name="button1" Content="Click Me">
<Button.Template>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Height="69" Stroke="Black" Width="69">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.004,1.044" StartPoint="0.739,0.25">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter Content="{TemplateBinding Content}" />
</StackPanel>
</ControlTemplate>
</Button.Template>
</Button>
See Using Control Templates to Customize a Control's Look and Feel