|
Hi,
I have a wpf window containing a Tabcontol with 2 tab items. Both tab items contain a datagrid and some additional buttons and textboxes. I can't seem to find an event for the tab control that only fires when you select the tab item at the top. SelectionChanged fires for any item that I select in the tab item. I need my datagrid to bind to a new datatable whenever its host tab is selected. Please Help!
|
|
|
|
|
A few days ago JSOP mentioned something like this. Look here[^]
|
|
|
|
|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) I created a new TabItem class, like so:
public class UDPTabItem : TabItem
{
public bool IsActive { get; set; }
public static readonly RoutedEvent ActivateEvent = EventManager.RegisterRoutedEvent("Activate",
RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(UDPTabItem));
public event RoutedEventHandler Activate
{
add { AddHandler(ActivateEvent, value); }
remove { RemoveHandler(ActivateEvent, value); }
}
private void RaiseActivateEvent()
{
RoutedEventArgs eventArgs = new RoutedEventArgs(UDPTabItem.ActivateEvent);
RaiseEvent(eventArgs);
}
public static readonly RoutedEvent DeactivateEvent = EventManager.RegisterRoutedEvent("Deactivate",
RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(UDPTabItem));
public event RoutedEventHandler Deactivate
{
add { AddHandler(DeactivateEvent, value); }
remove { RemoveHandler(DeactivateEvent, value); }
}
private void RaiseDeactivateEvent()
{
RoutedEventArgs eventArgs = new RoutedEventArgs(UDPTabItem.DeactivateEvent);
RaiseEvent(eventArgs);
}
public UDPTabItem()
{
this.IsActive = false;
}
public void ActivateTab(bool activate)
{
IsActive = activate;
if (this.IsActive)
{
RaiseActivateEvent();
}
else
{
RaiseDeactivateEvent();
}
}
protected override void OnSelected(RoutedEventArgs e)
{
ActivateTab(true);
base.OnSelected(e);
}
protected override void OnUnselected(RoutedEventArgs e)
{
ActivateTab(false);
base.OnUnselected(e);
}
}
You may need to massage it since I had to cut out some stuff for use here.
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
Thank you very much. I'm still new to WPF and I'm still getting used to the new event model. So far I'm quite impressed...
|
|
|
|
|
I've only been doing it since April, and I'm not impressed...
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
When we use the class library in silverlight application, the library must be silverlight class library.
Now I have a normal c# library project,part of it will use in silverlight.
Anybody knows how to do it ?
|
|
|
|
|
If you do a search for "Slverlight assembly' you will find many solutions. Here is the solution from a Microsoft monitored newsgroup developer:
How to add non-silverlight assemblies to a silverlight project[^]
The problem is that the both use a diffrent runtime CLR version.
I have a silverlight road map diagram which shows the difrences in silverlight CLR versions.
Composit Silverlight Architecture[^]
If your solution requires the code to run in the standard .NET runtime you can create a webservice for that code and then serialize the results bac to the client.
Additionally, if you really want all the features of the .NET runtime you could create your own WPF container hosted as an ActiveX add-on. However you open the browser to security issues which the Silverlight runtime protects you from.
Hosting WPF in a Win32 Application[^]
|
|
|
|
|
SOLUTION:
I had to do this in the Completed event handler:
void CollapseAnimator_Completed(object sender, EventArgs e)
{
GenericAnimationEnd(false);
}
void ExpandAnimator_Completed(object sender, EventArgs e)
{
GenericAnimationEnd(true);
}
private void GenericAnimationEnd( bool expanding)
{
double height = this.expandingGrid.ActualHeight;
this.CollapseAnimator.FillBehavior = FillBehavior.Stop;
this.ExpandAnimator.FillBehavior = FillBehavior.Stop;
this.expandingGrid.Height = height;
}
------------------------------------------
Last week, I posted a message about how a property is being frozen after animating a control. I have since moved the relevant code to a sample application. If anyone feels like looking at it. I would love to know what I'm doing wrong.
WIDTH ALERT - I didn't bother reformatting it, so the posted code might be wider than your screen. Simply create a new WPF application called "AnimateSample" and replace the contents of the appropriate files with the code below.
Here's Window1.XAML:
<Window x:Class="AnimateSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Width="800" Height="600">
<Window.Resources>
<Storyboard x:Key="AnimateGridExpand">
<DoubleAnimation To="300" Duration="0:0:0.2" Storyboard.TargetName="expandingGrid" Storyboard.TargetProperty="Height" />
</Storyboard>
<Storyboard x:Key="AnimateGridCollapse">
<DoubleAnimation To="100" Duration="0:0:0.2" Storyboard.TargetName="expandingGrid" Storyboard.TargetProperty="Height" />
</Storyboard>
</Window.Resources>
<Grid>
<Button Name="buttonGrowWithAnimation" Width="150" Height="23" Margin="20,5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="buttonGrowWithAnimation_Click">Grow With Animation</Button>
<Button Name="buttonGrowWithoutAnimation" Width="150" Height="23" Margin="0,5,20,0" HorizontalAlignment="Right" VerticalAlignment="Top" Click="buttonGrowWithoutAnimation_Click">Grow Without Animation</Button>
<Grid Name="expandingGrid" Margin="0,34,0,0" Height="100" VerticalAlignment="Top">
<Border Name="border1" BorderThickness="2" CornerRadius="6,6,6,6" Background="LightSlateGray" BorderBrush="Black">
<CheckBox Height="16" Name="checkBox1" Width="120">CheckBox</CheckBox>
</Border>
</Grid>
</Grid>
</Window>
And here's Window1.cs:
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Windows.Media.Animation;
namespace AnimateSample
{
public partial class Window1 : Window
{
public Storyboard ExpandAnimator { get; set; }
public Storyboard CollapseAnimator { get; set; }
public bool Expanded { get; set; }
public int OriginalZIndex { get; set; }
public double HeightChangeValue { get; set; }
public Window1()
{
InitializeComponent();
this.Expanded = false;
this.ExpandAnimator = ((Storyboard)TryFindResource("AnimateGridExpand")).Clone();
this.CollapseAnimator = ((Storyboard)TryFindResource("AnimateGridCollapse")).Clone();
DoubleAnimation daExpand = (DoubleAnimation)ExpandAnimator.Children[0];
DoubleAnimation daCollapse = (DoubleAnimation)CollapseAnimator.Children[0];
this.HeightChangeValue = (double)daExpand.To - (double)daCollapse.To;
Debug.WriteLine("\n---------------------------------------------------------------------------------");
Debug.WriteLine("Application Starts");
Debug.WriteLine("---------------------------------------------------------------------------------");
Debug.WriteLine(string.Format("HeightChangeValue = {0:0.0}", this.HeightChangeValue));
}
private void buttonGrowWithAnimation_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("----");
Debug.WriteLine((this.Expanded)?"Expanded" : "Collapsed");
Debug.WriteLine("Setting animation target to the grid");
Storyboard.SetTarget(this.ExpandAnimator, this.expandingGrid);
Storyboard.SetTarget(this.CollapseAnimator, this.expandingGrid);
if (this.Expanded)
{
Debug.WriteLine("Collapsing with animation");
this.CollapseAnimator.Begin(this);
}
else
{
Debug.WriteLine("Expanding with animation");
this.ExpandAnimator.Begin(this);
}
this.Expanded = !this.Expanded;
Debug.WriteLine((this.Expanded)?"Expanded" : "Collapsed");
}
private void buttonGrowWithoutAnimation_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("----");
Debug.WriteLine((this.Expanded)?"Expanded" : "Collapsed");
Debug.WriteLine("Setting animation target to null");
Storyboard.SetTarget(this.ExpandAnimator, null);
Storyboard.SetTarget(this.CollapseAnimator, null);
if (this.Expanded)
{
Debug.WriteLine("Collapsing WITHOUT animation");
this.expandingGrid.Height = Math.Max(100d, this.expandingGrid.ActualHeight - this.HeightChangeValue);
}
else
{
Debug.WriteLine("Collapsing WITHOUT animation");
this.expandingGrid.Height = this.expandingGrid.ActualHeight + this.HeightChangeValue;
}
this.Expanded = !this.Expanded;
Debug.WriteLine((this.Expanded)?"Expanded" : "Collapsed");
}
}
}
"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." - Jason Jystad, 10/26/2001
modified on Monday, June 15, 2009 5:03 PM
|
|
|
|
|
I'm fairly new to WPF/WCF/C# so the solution may be obvious to some experts out there.
I have a WPF application with simple TextBlocks that are bound to a custom data object that is being updating by a WCF service, the service sends me a fresh object with all new info periodically. The initial binding work fine, and when I receive a new object from the service, I want to be able to just set my object reference to that new object (not each property one at a time). This however breaks my bindings as they are still displaying the information from the previous object. If I rebind the exact same way as before, they update to the new refence.
Simple example (not perfect syntax, just to help explain):
public class MyData : INotifyPropertyChanged {
private int randomInt = [some random int]
//constructor sets randomInt to some random integer
//get set methods are here and call OnPropertyChange correctly
}
//WPF Code behind
MyData myData = new MyData;
Binding b = new Binding(); b.Source = "myData"; b.Path = "randomInt";
this.SomeTextBlock.SetBinding(TextBlock.TextProperty, b);
//all works great here
myData.randomInt = [another random int]
//also works great, TextBlock updates;
myData = new MyData(); //would create a new randomInt int with new value
//TextBlock doesn't update, if new binding is created and set it works fine
//want to be able to set myData object to a new instance of the class, but keep the bindings
I believe that on receiving a new data object, running through all the properties and setting my current data object properties to the new values would work great, but I will have many data objects coming fairly frequently so I'd rather not just set each one individually
I've explored several ideas that i had, but came up empty handed. Any ideas or tricks on if/how this could be done?
|
|
|
|
|
I'd use the DataContext property at some element up the tree so all bindings
below that spot in the tree can use the same bindings without reconstructing the
bindings every time you get new data.
Then it's as simple as
MyData myData = new MyData;
someElement.DataContect = myData;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the quick response Mark.
After playing around with the DataContext it seems like that could work decently well.
I do have multiple data sources that drive a single WPF Control, but with a little grouping of visual objects I think it could work out well.
Appreciate it.
Dan
|
|
|
|
|
Hi,
I have been reading posts on this forum, reading MSDN articles, playing with WPF and SilverLight demos, etc. Reading some of the WPF and SilverLight tutorials here on CP.
Okay, so I'm an old dog who's comfortable in WinForms and C#, who's not that hungry for eye-candy, and I want to invest in learning new mantras for the Angelic and Daemonic entities who mediate between Mankind and DirectX :
If you were advising someone new to actually getting their hands dirty-deep in SilverLight or WPF, with a view to maximizing their usable skill set a year from now (which is I when I think the technology will be "ripe" [and the dust of the Vista-lemmings stampede over the cliffs of Weven has subsided] ) :
If, as I get the message from here and elsewhere, SilverLight is a browser-centric secure-playpen which is a sub-set of WPF, it would seem logical to invest in WPF first and then segue as the song changed to downsize to SilverLight ... mmm ...
Or perhaps SilverLight is a good set of training wheels for WPF ... mmm ...
Obviously I'm not in a situation where my work requires me to use/study one or the other.
I lean toward WPF with the idea of writing essentially client-side apps that ... when the user is on-line ... and at the user's discretion ... can interact with web resources.
I have to admit I find the idea of SilverLight apps meta-morphing into deskstop apps interesting from a security point of view, and I also wonder what I could do in SilverLight that I could not do by using SilverLight as necessary inside a WPF app.
Appreciate any thoughts, and I apologize if this message is so "quantum frothy" that it is a bit OT here.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
BillWoodruff wrote: the idea of SilverLight apps meta-morphing into deskstop apps interesting from a security point of view
Not sure what you mean there, but Silverlight apps are always going to run in the
browser playpen, even the desktop-launchable ones in 3.0.
Which one you learn first, I don't know. Start with WPF then you're dissapointed when you use
the stripped down Silverlight version. Start with Silverlight - get used to playing in the sandbox,
then go to WPF and it's a bright new world with so much more you can do Either way, the
UI basics are similar.
I'd start with the one you'll get most use out of to start - WPF for native windows apps,
or Silverlight for cross-platform browser based apps.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks, Mark,
I just got an e-mail notice of a free white-paper from Wintellect[^] comparing differences between WPF and SilverLight that I think will answer many questions for me (I have no connection with Wintellect). I downloaded it (it's a .pdf file). It's 69 pages and includes VB and C# code snippets.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Hi,
Anybody knows how can i control the scroolbar width in a WPF listbox?
Tanks for your help!
|
|
|
|
|
WPF controls are known as lookless controls. This means that you can edit the individual parts of a control. Take a look here[^] to get some ideas.
"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
|
|
|
|
|
Pete O'Hanlon wrote: WPF controls are known as lookless controls.
I think they came up with this description because the designer is crap and nobody uses it.
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
I need to write a WCF service to consume a large excel sheet (having in excess of 70,000 records). Bascially the client (a WPF Desktop application) needs to read the excel spreadsheet in a Data Set and perform validation against a schema. Once validated the client needs to send the data to the WCF service.
The service then needs to insert the data in the database (simple inserts - one excel row becomes a row in the database table).
What options (transport type and bindings) do I have for consuming the "huge" excel files EFFICIENTLY within the WCF Service?
Regards,
Vipul Mehta
|
|
|
|
|
I use DataStreams
http://www.csvreader.com/[^]
It has to read the whole excel spreadsheet into memory first though but once done it is very simple and fast to read each row and do what you will with it.
|
|
|
|
|
hi..
i have two treeviews in my wpf application. and my both treeview contains hierarchical datatemplate.
The Item template has one stack panel in which i have one image and a textblock displaying data..
Now my problem is,
when i select particular node in one treeview and after that when i select select particular node in another treeview then the selected node on first treeview's background become gray..
Any idea?? ![Sigh | :sigh:](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_sigh.gif)
|
|
|
|
|
It becomes gray to indicate it is the SelectedItem of the TreeView but the particular TreeView is not currently in focus.
|
|
|
|
|
So is there anyway to remove it or replace gray color with some another color?
|
|
|
|
|
|
So, I have a custom slider. The body of the slider is all buttons, and these are at the top of the Z order. However, my tracker hangs below the slider, so it has a main tracking area, which is not on top of these buttons, in the sense of z, it's below them, in the sense of y.
This is my template:
<Track.Thumb>
<Thumb >
<Thumb.Template>
<ControlTemplate>
<Grid Margin="0,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Width="30" Margin="-8,0,-8,-25">
Where-ever in this tree I place an event for mouse up, it fires only for the right button, not the left. How do I catch the left button ? What I am doing is, I have a slider which moves smoothly, but when the user stops scrolling, I want to animate to one of a number of fixed positions. I am also animating a slide up when the user clicks one of the buttons ( this part works fine ).
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
modified on Monday, June 15, 2009 6:28 AM
|
|
|
|
|
Christian Graus wrote: This is my template:
<Image Grid.Row="0" Width="30" Margin="-8,0,-8,-25">
And it's invisible, I see.
"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
|
|
|
|
|