wpf

Why is the SelectTemplate Method run 2 times in debug mode?

Hello, debuging this class the SelectTemplate Method is run 2 times, but why? The first time the item is always null. public class PersonDataTemplateSelector : DataTemplateSelector { public override DataTemplate SelectTemplate(object item,DependencyObject container) { if (item is Person) { Person pe...

Measure label size

I'm implementing a custom control with some labels on it and I need to measure the size of those labels to have an optimal layout. In this way I can properly show the control for each font and font size. Could you tell me how can I do that, please? Thank you. ...

WPF / Silverlight Binding when setting DataTemplate programically

I have my little designer tool (my program). On the left side I have TreeView and on the right site I have Accordion. When I select a node I want to dynamically build Accordion Items based on Properties from DataContext of selected node. Selecting nodes works fine, and when I use this sample code for testing it works also. XAML code...

Translate ImageButton from C# to XAML

I worked out the C# code to create an ImageButton (below) that has three images (one base-image and two overlays) and three text boxes as the face of the button. I am inheriting from the Button class, which unfortunately includes several components that I didn't realize would surface until after coding and need to remove, namely the bri...

WPF MediaPlayer doesn't play M4A?

I am trying to use a MediaPlayer instance to play M4A files. For those of you that aren't familiar, MediaPlayer is the non-XAML version of a MediaElement. There are pretty much the same, but I don't want any XAML, so I use a MediaPlayer instead. Anyways, it plays some M4A files just fine. The NaturalDuration of other M4A files is 0, but ...

WPF: Adorner Hit Testing / MouseDown Event

Hello, I have an Adorner which adornes a Border (please see screenshot below). The MouseDown Event for the Adorner is however only raised, when clicking on an element in the adorner. I need the MouseDown Event to be raised, when clicking on any place in the adorner above the adorned element. How can this be done? Do I have to add an tra...

How Dispatcher differs from the background thread ?

How Dispatcher concept in .NET 3.5 in WPF differs from the background thread in .NET 2.0 ? For example what will be difference between statements below: delegate.Invoke/BeginInvoke AND this.dispatcher.Invoke/BeginInvoke ...

How to bind Dictionary with ComboBox and textbox?

I have a Dictionary<String,Person>, where Person is a class, defined below String role; public class Person { public string firstname{ get; set; } public string lastname{ get; set; } public string city{ get; set; } } My question is how to bind the Dictionary key: String with a ComboBox, meanwhile. have the Dictionary va...

The best way to organize WPF projects

Hello everybody, I've started recently to develop a new software in WPF, and I still don't know which is the best way to organize the application, to be more productive with Visual Studio and Expression Blend. I noticed 2 annoying things I'd like to solve: I'm using Code Contracts in my projects, and when I run my project with Expres...

C#/WPF - RoutedEvent in WPF class that isn't a UIElement

I have a class that needs to notify that something significant has occured. The class is in a WPF-project, even though this specific class, is lookless (and doesn't inherit from UIElement, neither directly or indirectly). Normally, I just register a RoutedEvent to get this functionality but as this class neither has AddHandler nor Remo...

Wpf: Treeview updated or datatemplate applied event

The scenario is: In my Window, I have a TreeView, each item of this represents different user-defined types, So I have defined DataTemplate for each type. These DataTemplates are using user-controls and these usercontrols are binded with properties of user-defined types. As simple, TreeView maps a Hierarchical Data Structure of user-defi...

How can I tie a WPF Command to a MouseEnter event?

I need to tie a WPF-Command to the MouseEnter event of a Stackpanel. How can I do that? ...

How to Animate a Gradient on a Path to visualize data flow in WPF/WCF app

I have an interesting project where several "nodes" on a cnavas are connected via a Path similiar to a mindmap tree. The path is used to visualize the connection state between two nodes. Red means the nodes are disconnected, green means they're connected. The next step would be to illustrate data flow (from A to B or B to A) using that p...

WPF ICommand over a button

Hi, I have implemented a custom IComand class for one of my buttons. The button is placed in a page 'MyPage.xaml' but its custom ICommand class is placed in another class, not in the MyPage code behind. Then from XAML I want to bind the button with its custom command class and then I do: MyPage.xaml: <Page ...> <Page.Com...

DataGridCheckBoxColumn immediate binding

Hi. I'm using the WPF Toolkit Datagrid and have one column which is a DataGridCheckBoxColumn bound to a bool property on my ViewModel. My problem is that I wan't the property to get it's value updated immediately when the user checks or unchecks the checkbox. Now you have to navigate away from the cell in order to have the property up...

Override default markup extensions

I have written custom markup extesions, but what if I need to override an markup extension already defined? For example, I need to serialize StaticResources references and not the values when using XamlWriter.Save(object obj) method, so I guess what I need is to write a custom markupextension inheriting from ‘StaticResourceExtension’ tha...

WPF SDK DownLoad (For offline Usage)

Is there SDK available to download for wpf, as I wanto read that SDK when I don't have internet. Any idea about it, from where can I download SDK for WPF. ...

How to organise input for many classes

I have one abstract class and many child classes. In child classes are from 2 to 20 members which must be filled by user. What the best way to do this using OOP? Make form for each child class? Or hide and unhide many input elements and labels? Is there some best way? I using WPF and C# ...

WPF Binding to code behind methods

Hi all, This is annoying - I know how I'd do it in web... I have a wpf image and I want to bind it's source property to a method, and pass in a property from it's bound item. IE. <image source="GetMySource({binding name})" /> Where GetMySource is protected string GetMySource(string name) { return "images/"+name+".png"; } ...

WPF Bind User Control Coordinates

Another beginner WPF question from me :) Ok, so I have a User Control added to a Canvas. In another area of the application I have two TextBoxes that will get 2 values : X and Y. I need a two-way binding between the user control's top left corner coordinates and those 2 textboxes. I don't mind implementing a Converter or doing some cal...