|
C# WPF
I have this lines of code.
mediaElement.Source = new Uri(fileName, UriKind.Absolute);
mediaElement.Play();
Sometimes mediaElement plays the file (mp3 or video)... and sometimes will play that file after a while (3 minutes ++ like the file that just was played previously)
I tried that to put mediaElement.Stop(); or to stop the graph (like in directShow) but no results...
Please... please someone know why this lag?
|
|
|
|
|
How to create the WPF Web browser application, in which user can navigate through multiple pages?
|
|
|
|
|
As you're using WPF, you will need XAML, as well as some code.
Seriously, what have you tried ?
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
|
|
|
|
|
Tell me how can i do that?
|
|
|
|
|
I assume you're joking ? What was the point of your original post ?
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
|
|
|
|
|
|
thank UUUU
|
|
|
|
|
Hi,
I am working on WPF. In this I will dynamically add images to a stack panel. During this process when I select an element and click a button, then the another image which is same as the selected element should be added.
That is I have to copy the selected UI element in another UIElelement and then I have to add this new UIElelment to the Stack panel. For this I wrote code like this:
UIElement DuplicateImg = selectedElement;
spanel.Children.Insert(GetSlideIndexinStackPanel(selectedElement), DuplicateImg);
but for this I am getting an error
"Additional information: Specified Visual is already a child of another Visual or the root of a CompositionTarget."
If anyone have any idea to solve this please reply me
Thanks in advance
|
|
|
|
|
|
Can't you just create a new Image object, and then use the same source as the original?
"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 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[^]
|
|
|
|
|
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!
|
|
|
|
|