|
I never worked with DataGrid but I would take a look at the SortCommand event of the DataGrid.
Greetings
Covean
|
|
|
|
|
I am using Silverlight 3, and there is no SortCommand event with DataGrid. Thanks for your reply.
|
|
|
|
|
Sorry my fault, I didn't mentioned that I answered to a silverlight question.
Sorry for that.
Greetings
Covean
|
|
|
|
|
Guys,
I'm trying a simple animation in code behind with a start/stop button.
However, my animation does not want to stop for some reason (despite MSDN showing me the same as I did).
It's probably something small I did wrong, but I can't find it.
I'm also a litte puzzled with the PropertyPath object.
Many thanks.
private void btn_start_Click(object sender, RoutedEventArgs e)
{
if(sb == null){
sb = new Storyboard();
da = new DoubleAnimation();
da.From = 0;
da.To = 360;
da.Duration = new Duration(new TimeSpan(0, 0, 10));
da.RepeatBehavior = RepeatBehavior.Forever;
rectangle_animation.RenderTransform = new RotateTransform();
rectangle_animation.RenderTransformOrigin = new Point(0.5, 0.5);
rectangle_animation.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, da);
sb.Children.Add(da);
Storyboard.SetTargetProperty(da, new PropertyPath("Background.Opacity"));
sb.Begin(this, true);
}
else{
sb.Resume(this);
}
btn_stop.Visibility = Visibility.Visible;
btn_start.Visibility = Visibility.Hidden;
}
private void btn_stop_Click(object sender, RoutedEventArgs e)
{
if(sb != null){
sb.Pause(this);
}
btn_stop.Visibility = Visibility.Hidden;
btn_start.Visibility = Visibility.Visible;
}
|
|
|
|
|
I think it is that you are using the pause method look at this from MSDN:
This method pauses the storyboard, but has no discernible effect if it
is not active or currently paused. As a side effect, all associated
children are also paused.
A controllable storyboard can pause, resume, seek, stop, and be removed. To
make a storyboard controllable in code, you must use the appropriate
overload of the storyboard's Begin method and specify true to make it
controllable. For an example, see How to: Control a Storyboard After It
Starts.
Try using the stop method instead.
|
|
|
|
|
thanks, in meantime I was able to add a second animation (color).
I probably set the PropertyPath wrong.
I used Background.color as propertypath for the color animation, which puts the window background in color, animates it AND pauses correctly (while the rotation continues).
My goal is however to rotate and change color of the rectangle only. I feel I'm near, but the PropertyPath is still illuding me a little.
(for the record, one of the errors was indeed that you have to use the overloaded Begin method with Controllable set to True.)
|
|
|
|
|
FYI, I got it to work. Here's the code.
The result is that only the Rectangle will turn and change color when starting the animation. They both stop when stopping the animation.
if(sb == null){
sb = new Storyboard();
da = new DoubleAnimation();
da.From = 0;
da.To = 360;
da.Duration = new Duration(new TimeSpan(0, 0, 10));
da.RepeatBehavior = RepeatBehavior.Forever;
rectangle_animation.RenderTransform = new RotateTransform();
rectangle_animation.RenderTransformOrigin = new Point(0.5, 0.5);
ca = new ColorAnimation();
ca.From = Colors.Red;
ca.To = Colors.Blue;
ca.Duration = new Duration(new TimeSpan(0, 0, 10));
ca.RepeatBehavior = RepeatBehavior.Forever;
ca.AutoReverse = true;
if(rectangle_animation.Fill == null){
rectangle_animation.Fill = new SolidColorBrush();
}
this.RegisterName("rectangle_angle", rectangle_animation.RenderTransform);
Storyboard.SetTargetName(da, "rectangle_angle");
Storyboard.SetTargetProperty(da, new PropertyPath(RotateTransform.AngleProperty));
this.RegisterName("rectangle_brush", (SolidColorBrush)rectangle_animation.Fill);
Storyboard.SetTargetName(ca, "rectangle_brush");
Storyboard.SetTargetProperty(ca, new PropertyPath(SolidColorBrush.ColorProperty));
sb.Children.Add(da);
sb.Children.Add(ca);
sb.Begin(this, true);
}
else{
sb.Resume(this);
}
btn_stop.Visibility = Visibility.Visible;
btn_start.Visibility = Visibility.Hidden;
}
private void btn_stop_Click(object sender, RoutedEventArgs e)
{
if(sb != null){
sb.Pause(this);
}
btn_stop.Visibility = Visibility.Hidden;
btn_start.Visibility = Visibility.Visible;
}
|
|
|
|
|
Hey could you comment the code or put some highlights in so theirs can easily identify what your solution was?
Also if you use the pre tag make sure that the code fits on the page, if you see a scroll bar at the bottom you will need to adjust the formatting.
I would like to know what you had to do....
Good to see you got it working....
|
|
|
|
|
Reformat? No way, that would come out more ugly, but here's the code with additional comments.
Note I continued playing with it.
private void btn_start_Click(object sender, RoutedEventArgs e)
{
if(sb == null){
sb = new Storyboard();
da = new DoubleAnimation();
da.From = Convert.ToInt32(txtbox_anglefrom.Text);
da.To = Convert.ToInt32(txtbox_angleto.Text);
string [] timespan = txtbox_duration.Text.Split(new string [] {":"}, StringSplitOptions.None);
da.Duration = new Duration(new TimeSpan(Convert.ToInt32(timespan[0]), Convert.ToInt32(timespan[1]), Convert.ToInt32(timespan[2])));
da.RepeatBehavior = RepeatBehavior.Forever;
da.AutoReverse = true;
rectangle_animation.RenderTransform = new RotateTransform();
rectangle_animation.RenderTransformOrigin = new Point(0.5, 0.5);
ca = new ColorAnimation();
ca.From = Colors.Red;
ca.To = Colors.Blue;
ca.Duration = new Duration(new TimeSpan(Convert.ToInt32(timespan[0]), Convert.ToInt32(timespan[1]), Convert.ToInt32(timespan[2])));
ca.RepeatBehavior = RepeatBehavior.Forever;
ca.AutoReverse = true;
if(rectangle_animation.Fill == null){
rectangle_animation.Fill = new SolidColorBrush();
}
this.RegisterName("rectangle_angle", rectangle_animation.RenderTransform);
Storyboard.SetTargetName(da, "rectangle_angle");
Storyboard.SetTargetProperty(da, new PropertyPath(RotateTransform.AngleProperty));
this.RegisterName("rectangle_brush", (SolidColorBrush)rectangle_animation.Fill);
Storyboard.SetTargetName(ca, "rectangle_brush");
Storyboard.SetTargetProperty(ca, new PropertyPath(SolidColorBrush.ColorProperty));
sb.Children.Add(da);
sb.Children.Add(ca);
sb.Begin(this, true);
txtbox_duration.IsEnabled = false;
txtbox_anglefrom.IsEnabled = false;
txtbox_angleto.IsEnabled = false;
}
else{
sb.Resume(this);
}
btn_stop.IsEnabled = true;
btn_start.IsEnabled = false;
}
private void btn_stop_Click(object sender, RoutedEventArgs e)
{
if(sb != null){
sb.Pause(this);
}
btn_stop.IsEnabled = false;
btn_start.IsEnabled = true;
}
private void btn_close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void btn_restart_Click(object sender, RoutedEventArgs e) {
sb.Stop(this);
sb = null;
this.UnregisterName("rectangle_angle");
this.UnregisterName("rectangle_brush");
btn_stop.IsEnabled = false;
btn_start.IsEnabled = true;
txtbox_duration.IsEnabled = true;
txtbox_anglefrom.IsEnabled = true;
txtbox_angleto.IsEnabled = true;
}
there, I hope that's useful
|
|
|
|
|
Do a search on XAML templates, you can do most of what you are doing with a template and triggers....
Google Friendly search: 'xaml templates WPF C# .NET site:microsoft.com'
|
|
|
|
|
I know, the test was to see if I could do it in code behind. Personally I have the feeling it is more flexible.
|
|
|
|
|
I have a WPF app with sqlserver 2008 database. I have several textboxes bound to date fields in the database as so :
TextBox Height="28" Name="textBoxApprovedDate" Width="120" Text="{Binding Path=ApprovedDate,StringFormat=dd/MM/yyyy}
The output from the database is fine, but it will not allow me to input a date in UK format ie dd/MM/yyyy.
How can I solve this?
TIA Mike
|
|
|
|
|
Have a look at the datepicker control[^]. You can set the cultureInfo to en-UK if they have such a property available.
|
|
|
|
|
Hi,
Another problem with VS 2008 WPF designer. Program runs fine, but designer won't load the UI. Here is the shortest possible example to demonstrate the problem.
App
<pre>
<Application x:Class="UCTester.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources\Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
</pre>
Window1
<pre>
<Window x:Class="UCTester.Window1"
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
xmlns:local="clr-namespace:UCTester"
Title="Window1" Height="300" Width="300">
<DockPanel>
<local:GridViewer/>
</DockPanel>
</Window>
</pre>
GridViewer
<pre>
<UserControl x:Class="UCTester.GridViewer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Border Style="{StaticResource stlListViewBorder}"></Border>
</UserControl>
</pre>
Styles
<pre>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="stlListViewBorder" TargetType="{x:Type Border}">
</Style>
</ResourceDictionary>
</pre>
Now, in the GridViewer, if all you have is <Border></Border>, all is good. The code runs, and Window1 loads in designer. If, however, in the GridViewer, <Border></Border> is replaced by <Border Style="{StaticResource stlListViewBorder}"></Border>, the code still runs, but Window1 no longer loads in the designer.
Why? What am I missing? Or is this a bug in WPF? If someone could figure this out it would be really helpful. Problem is, if the designer is this problematic when you are dealing with code this simple, it will be tough to use as a tool when writing production code.
Your thoughts will be greatly appreciated.
Peter Battelino
|
|
|
|
|
Hi
There is a list box with some items in it. Also there is a grid with 3x3 matrix. The user will be dragging an item and dropping on one the cells of grid.
Most of the samples I found are about dragging-dropping from one listbox to another listbox. But I want to drop in one cell of grid. How can I acheive this?
Please advise. thanks
PJ
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
I think this might have to do with FrameworkElements and FrameworkContentElements have a look at my tip/trick
Build a bridge between FrwmeworkElement and FrameworkContentElement[^]
it might help, but this is just a buck wild shot guess. There is also a link to the main article that I get the info from on drag and drop between these elements.
~TheArch
|
|
|
|
|
Hi
I am trying to develop a multi player game over the internet. A 2 to 4 players game in WPF.
1. Since I want to make it available via browser also at some point, is "WPF-Browser Application" a good choice?
2. What approach I can follow to maintain the connectivity between players? Peer to peer or do I need to maintain a server in between all players?
3. How can I transfer the information across all instances and maintain data state?
Please advise. thanks
PJ
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
If you use peer-to-peer, at least one player in every peer-to-peer
pair is going to need to be a "server" to esatablish a connection...
Do you want users to have to configure firewalls and or HTTP
servers (or similar) just to play the game?
I would think a server would make items 2 and 3 much easier
on the users. Using an HTTP server is best, since most
machines are configured to allow internet access. And .NET
makes it easy to implement such servers.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hi
till this is WPF is windows. u can use silverlight applications for develop applications regarding game applications.
Thanks & Regards
Nagi Setty A
|
|
|
|
|
Hi
I have a 3x3 matrix grid. If a user on particular cell, how can I identify the cell cordinates after click?
Please advise. thanks
PJ
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
mittalpa wrote: If a user on particular cell, how can I identify the cell cordinates after click?
Usually by handling events in an element that's in the cell,
not on the grid itself.
You could probably also loop through the column and row
definition collections on the grid and hit-test against
the Actual/Width/ActualHeight values.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I'm gonna work with Model-View-ViewModel in my applications.
I've created this WPF application[^] with MVVM.
Would you please glimpse it and say :
Have I done it in the right way or not ?
Many thanks in advance.
|
|
|
|
|
If you have done that much post it as an article and do a write up on it. Microsoft has a MVVM demo application that shows correct MVVM.
Also do a search for 'if Heinikin could' Here at The Code Project, or just look at my profile and look at Barrbra's stuff on MVVM, he made some mods to make it a 'cinch'
~TheArch
|
|
|
|
|
I have built a small application using Silver Light 3. The app contains a website with SilverLight enabled WCF services. Everything works great when debugging. But when I deploy it to the server the application generates an exception every time it tries to use the web service.
I tried changing the location of the reference in ServiceReferences.ClientConfig to the location of the published service before deploying, but that did not work.
Anyone know how to go about debugging this? The javascript error message doesn't tell me much. Is there any good way to handle silverlight errors?
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; MS-RTC EA 2)
Timestamp: Mon, 25 Jan 2010 19:03:17 UTC
Message: Unhandled Error in Silverlight 2 Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at SettlementGainLoss.PricingData.GetTopHatTerminalsCompletedEventArgs.get_Result()
at SettlementGainLoss.Views.MapPrices.client_GetTopHatTerminalsCompleted(Object sender, GetTopHatTerminalsCompletedEventArgs e)
at SettlementGainLoss.PricingData.PricingDataServiceClient.OnGetTopHatTerminalsCompleted(Object state)
Line: 1
Char: 1
Code: 0
URI: http://devintranet.buckeye.com/sl3Example/Home.aspx
Message: Unhandled Error in Silverlight 2 Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at SettlementGainLoss.PricingData.GetProductsCompletedEventArgs.get_Result()
at SettlementGainLoss.Views.MapPrices.client_GetProductsCompleted(Object sender, GetProductsCompletedEventArgs e)
at SettlementGainLoss.PricingData.PricingDataServiceClient.OnGetProductsCompleted(Object state)
Line: 1
Char: 1
Code: 0
URI: http://devintranet.buckeye.com/sl3Example/Home.aspx
I didn't get any requirements for the signature
|
|
|
|
|
ToddHileHoffer wrote: I tried changing the location of the reference in ServiceReferences.ClientConfig to the location of the published service before deploying, but that did not work.
You also probably need changes in the web.config.
What does your web.config look like?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|