|
I am trying to animate the FontSize and the rotation of a TextBlock. The FontSize animates but I can not get the
text to rotate. Here is the XAML
<Window x:Class="WpfSameGame.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="600" Width="550" WindowStartupLocation="CenterScreen"
Loaded="Window_Loaded" Closing="Window_Closing">
<Window.Resources>
<DoubleAnimation
x:Key="StringFontSize"
To="20"
AccelerationRatio=".5"
DecelerationRatio=".5"
Duration="0:0:02"
Storyboard.TargetName="gameOver"
Storyboard.TargetProperty="FontSize"
/>
<DoubleAnimation
x:Key="StringRotation"
To="360"
AccelerationRatio=".5"
DecelerationRatio=".5"
Duration="0:0:2"
Storyboard.TargetName="gameOver"
Storyboard.TargetProperty="TextEffects[0].Transform.Angle"
/>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" FontFamily="comic sans ms" FontStyle="Italic"
Foreground="Red" FontSize="20" HorizontalAlignment="Center"
VerticalAlignment="Center" Name="textBlk">
<Run FontSize="10" Name="gameOver" Text="" />
<Run>Score: </Run>
<Run Name="scoreText">0</Run>
</TextBlock>
<Button Width="70" Height="25" Click="NewGame_Click"
VerticalAlignment="Center" HorizontalAlignment="Right">NewGame</Button>
<UniformGrid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
Rows="12" Columns="12" Width="504" Height="504" Name="gameGrid" Background="Cyan">
</UniformGrid>
</Grid>
</Window>
Here is the relevant code behind
DoubleAnimation fsa = this.FindResource("StringFontSize") as DoubleAnimation;
DoubleAnimation sra = this.FindResource("StringRotation") as DoubleAnimation;
Storyboard sb = new Storyboard();
TextEffect te = new TextEffect();
te.Transform = new RotateTransform(0);
this.gameOver.Text = "Game Over ";
gameOver.TextEffects.Add(te);
sb.Children.Add(sra);
sb.Children.Add(fsa);
sb.Begin(this.textBlk);
|
|
|
|
|
You need to set the PositionCount of the TextEffect. te.PositionCount = this.gameOver.Text.Length;
|
|
|
|
|
Setting the "PositionCount" solved the problem. Thanks.
Now a second problem. With the animations defined as a window
resource, they run one time only. What do I have to reset in a
DoubleAnimation to reuse it?
For now I am creating the animations at run time. But I would
like to know how to reuse an animation.
|
|
|
|
|
Hi Experts,
I wanted to get the SelectedText on edit mode in WPF datagrid (i.e Active cell can be entire text or partial text selected by user within datagrid)
SelectedLength(Length of the selected text in datagrid cell), Selected Position (cursor position in datagrid cell). How these all values can be achieved in WPF datagrid. For better understanding please read the below example.
For Example: suppose user has double clicked datagrid in row 1 and col 2 position, data available on the selected position is Text. Consider user has selected only ext out of (Text). So my expected result should be
Selected Text: ext
Selected Position: 1
Selected Length: 3
Cell Text: Text
Thanks in advance
|
|
|
|
|
kartheesh wrote: Selected Text: ext
Selected Position: 1
Selected Length: 3
Cell Text: Text
A textbox provides these properties - not a text block.
A datagrid is composed of textblocks as cell components so this may not be possible until you style the datagrid differently.
|
|
|
|
|
If I was looking to do something more complex like this, I would consider rolling my own Blend behaviour or DependencyProperty that did this, and hook it up to the textboxes in the editable template. I would favour the Blend behaviour here as it is a lot easier to set up, and you are just going to be extending the TextBox control for this.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi Experts,
Appreciate if anybody can help me out with small code snippet.
Thanks in advance.
|
|
|
|
|
To give you an idea what a Behavior looks like, he's one I put together for selecting all text when a textbox gets focus. You will want to consider creating a variation on this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Interactivity;
namespace Goldlight.Extensions.Behaviors
{
public class SelectAllTextBehavior : Behavior<TextBox>
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.GotKeyboardFocus += new System.Windows.Input.KeyboardFocusChangedEventHandler(AssociatedObject_GotKeyboardFocus);
AssociatedObject.GotMouseCapture += new System.Windows.Input.MouseEventHandler(AssociatedObject_GotMouseCapture);
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.GotKeyboardFocus -= new System.Windows.Input.KeyboardFocusChangedEventHandler(AssociatedObject_GotKeyboardFocus);
AssociatedObject.GotMouseCapture -= new System.Windows.Input.MouseEventHandler(AssociatedObject_GotMouseCapture);
}
void AssociatedObject_GotMouseCapture(object sender, System.Windows.Input.MouseEventArgs e)
{
AssociatedObject.SelectAll();
}
void AssociatedObject_GotKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
{
AssociatedObject.SelectAll();
}
}
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks for the reply buddy,exactly what my requirement is i will explain you.
I have created mdi form in WPF with few menus like copy,cut,paste and in my active form i have datagrid control.
Using copy,cut and paste functionality from the menu options i wanted to modify the datagrid cell data. As of now to implement the same i am doing workaround by refering the below link:
http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-clipboard
Appreciate to get help in this regards.
Thanks & Regards
Kartheesh
|
|
|
|
|
Let me balance out the 1 that somebody has voted you with a 5.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
How do you generate classes from XAML in Visual Studio 2008?
I have a Silverlight project. The XAML has been written in Expression Blend. I am told that I can use Visual Studio to use the grid classes in the Page.xaml file (the whole solution is loaded into Visual Studio) to generate the .CS (C#) files in Visual Studio 2008 that correspond to the several <grid> classes in the XAML. How is this done? Is there a wizard somewhere that will do this for me? Do I have to do this by hand?
When I open the Page.Xaml file and click on the name of the <grid> node, (x:Name) and select, to view code, it takes me to a file without much meat on it:
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
}
Since each <grid> contains a lot of components, I was expecting more.
Am I supposed to expand on this class by hand and code all the methods for this "Page" class? Is there a tutorial that shows how to do this?
There are so many videos to look at http://expression.microsoft.com/en-us/cc197141.aspx but they all seem to be focused on Expression Blend rather than how to use the XAML from Expression Blend to make Classes or to build on these classes.
On the other hand, are their example or sample code of how to take a "public partial class Page : UserControl" in C# and build from it?
|
|
|
|
|
Xarzu wrote: Am I supposed to expand on this class by hand and code all the methods for this "Page" class? Is there a tutorial that shows how to do this?
Yes. The Xaml represents the UI design - but if you need to add your own business logic, you still need to write code.
The code you need to write depends on what you intend to do - but do a search on the internet and you will find quite a few samples.
|
|
|
|
|
You should give your components names (x:Name=... ). At that point you can refer to them in your cs code. So, if you did this in your XAML:
<Grid x:Name="LayoutRoot" />
You could do this in your cs code:
this.LayoutRoot.Background = new SolidColorBursh(Colors.Red);
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
When you design something in XAML, no real code gets added into this Page class until compile time. Then a hidden .g.cs file is created which adds the definitions of the components in.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi all,
I found several links for this but no definitive answer. Could you please tell me the reason
|
|
|
|
|
AFAIK, wsHttpBinding is not supported in silverlight - Silverlight supports the WS basic profile, which uses basicHttpBinding and not wsHttpBinding.
|
|
|
|
|
Something happened in the last week that prevents VS2008 from being able to debug ANY Silverlight apps (non-Silverlight can still be debugged normally). Last weekend, it worked fine. I did notice there was an update to .Net 3.5 and it also pushed the .Net4 Client Profile in the latest rounds of Microsoft updates (last week) but I don't know if this is the cause.
SOLUTION ============================
I found out what was wrong - I had an out-of-date pdb file in a 3rd party folder. When I replaced it with the appropriate file, everything was fine.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
modified on Monday, June 28, 2010 7:42 AM
|
|
|
|
|
Maybe this can help -
Goto the web project of your SL solution, right click on it and view the project properties.
Goto the Web option and ensure the Silverlight debugger is checked.
|
|
|
|
|
Hi, this thing is killing me..
I have object drag of type Field and I would like to bind it to a productsDataGrid 's property Drag in XAML. In codebehind it all works well :
public class Field : INotifyPropertyChanged
{
...
public string Value
...
}
public partial class MainPage : UserControl
{
public Field drag;
public MainPage()
{
drag = new Field();
drag.Value = "true";
productsDataGrid.Drag = drag;
but in XAML it's not.
<cont:DragGrid Name="productsDataGrid" Drag="{Binding drag, Path=Value}"/>
How to set this binding correct ?
|
|
|
|
|
Make Value a property, not a field.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi, sorry I didn't paste complete code of Field class, but Value is already a property
public class Field : INotifyPropertyChanged
{
private string _value;
public string Value
{
get {return _value;}
set
{
_value = value;
NotifyPropertyChanged("Value");
}
Edit: I deleted my last message, because I thought I worked the solution, so the question is still unanswered.
modified on Saturday, June 26, 2010 9:50 AM
|
|
|
|
|
ekimpl wrote: <cont:draggrid name="productsDataGrid" drag="{Binding drag, Path=Value}">
I did not see you setting the Datacontext for the xaml anywhere.
What is it set to?
|
|
|
|
|
I set DataContext in LayoutRoot
<UserControl x:Class="MFP.MainPage" ..... >
<UserControl.Resources>
<my:MainPage x:Key="mainpage"/>
</UserControl.Resources>
<Canvas x:Name="LayoutRoot" DataContext="mainpage" ...
|
|
|
|
|
private string _value; <br />
public string Value <br />
{ <br />
get {return _value;<br />
} <br />
set <br />
{ <br />
_value = value; <br />
NotifyPropertyChanged("Value"); <br />
}<br />
Move the property code to mainpage and try....
|
|
|
|
|
But the Value property is inside of class Field , so I can't move it.
|
|
|
|