wpf

How can I specify resources in an MVVM view model?

Suppose I want to show list of objects where each object should have a name and a suitable image (for example MenuItems with Icons, or buttons with text and image). All examples and programs exposed the image in the viewmodel as a path to a PNG file and then bound the Source of an Image to that. But what if I want to use vector images (...

General Observable Dictionary Class for DataBinding/WPF C#

Hello, I'm trying to create a Observable Dictionary Class for WPF DataBinding in C#. I found a nice example from Andy here: http://stackoverflow.com/questions/800130/two-way-data-binding-with-a-dictionary-in-wpf/800217 According to that, I tried to change the code to following: class ObservableDictionary : ViewModelBase { public O...

Now can I get a View to instantiate another View that appears above it like a DialogueBox?

I just completed a "dialogue-box solution" for my WPF/MVVM application in which the ViewModel changes its ViewModel properities, and the View uses triggers to accordingly display and hide the dialogue box, etc. From a UX experience it is satisfactory. However, the "dialogue box" that I use is a Border element which gets its Visibility p...

wpf: update multiple controls via dispatcher

I'm reading data from a serial port using an event listener from the SerialPort class. In my event handler, I need to update many (30-40) controls in my window with xml data coming over the serial port. I know that I must use myControl.Dispatcher.Invoke() to update it since it's on a different thread, but is there a way to update lots ...

Displaying a WPF window when the project is a dll, not an exe

How do I display a wpf window in my application when the application resides in a dll, not an exe? This project will be compiled to a dll and loaded into another application as an add-in. In WinForms, I would just have the following code: dim frmUserData as frmDataEntry = new frmDataEntry frmUserData.ShowDialog() How do I accomplish ...

WPF - Swapping ContentControl (relinking elements???)

I'm working on a custom panel control and one of the things I'm trying to have it do is swap it's content at run-time. There's two states to this control: Maximized and Normal. When the user clicks a button on the control the state switches. There's two properties on this control: MaximizedContent and MinimizedContent. When the button to...

Listen to child MenuItem Click

Is there a way for a parent MenuItem to be notified when a child MenuItem is pressed. For example, I you have <MenuItem Name='a'> <MenuItem Name='b' Header='...'/> </MenuItem> how can I add an event handler to a to be notified when b is clicked. Ideally, the Click event would be either a tunnel or bubble event but this is not the ...

What all should an expert C#/.Net/WPF developer know?

Hello everyone. I have some 5+ years' background in C++/Unix development. I have been trying my hand at C#/.Net/WPF based software development for some time now. I am at a stage where I can write functioning applications fluently, but am not sure how to take my skills to the next level. So, my question(s) to you all, especially to thos...

Convert HTML to XAML

Is there a way to convert HTML into XAML? I noticed that you can paste HTML into a RichTextBox and you can get the XAML by looking at the FlowDocument. However, this is a hack. Is there a better way? ...

How do you apply a Scale Translation to a DrawingContext?

I have a canvas with a scale translation applied in XAML. Using DrawingContext I draw lines on the canvas. I now need to add text to the screen. I thought with formatted text I could apply a translation, but neither Formatted Text or DrawingContext accepts RenderTransform. How do I apply a scale translation to the text so it will coun...

WPF ItemsControls Not Showing Collection When Using UserControl in DataTemplate

I am trying to use the MVVM model to create a test application. I have Customers and Orders. Now, I want to display Customers list and when the user click on the customer it should display the Order. It works perfectly when I use the following code: <StackPanel DataContext="{Binding Path=Customers}"> <ListBox IsSynchroni...

MVVM WPF Dividing the Views into Smaller Views

How do you go about dividing the views into smaller views. Let's say I have Customer object and each Customer can have Orders. Should I create a single view "CustomerOrderView" or should I create 3 views "CustomerOrderView", "CustomerView", "OrderView"? ...

Nested DataTemplates in ListBox

Is there any way to make a DataTemplate reference itself just from XAML? In this particular case trying to reference a DataTemplate from a ListBox contained within the same DataTemplate. Here is the solution I'd like, which doesn't work. <DataTemplate x:Key="nestedItem" DataType="{x:Type local:NestedItem}"> <Expander Header="{Bind...

Setting User Control's DataContext from Code-Behind

This should be pretty easy, but it throws VS2008 for a serious loop. I'm trying out WPF with MVVM, and am a total newbie at it although I've been developing for about 15 years, and have a comp. sci. degree. At the current client, I am required to use VB.Net. I have renamed my own variables and removed some distractions in the code b...

Using win32 in managed code

I have been using WPF for a few years now and don't have any experience with anything but managed code. I started writing an app that uses a lot of win32 interop and i started wondering if i was leaking memory or generally doing something stupid that i didn't know about... So i thought i would seek some advice! Is there any gotchas/tips...

WPF: Inheriting from HeaderedContentControl

I would like to create a simple control that inherits from HeaderedContentControl, and has some basic dependency properties called Title, Subtitle, Icon. I would like to be able to provide a default header template that databinds these properties. For this example, I have named this class HeaderedView. I am having trouble in providing a...

Is MVVM really useful?

I have read the MSDN article on MVVM and I am not really convinced. If the model already implements INotifyPropertyChanged/INotifyCollectionChanged, what's wrong with the View binding directly against the Model? It seems the extra ModelView introduces some code without much benefit. Am I missing something? ...

WPF Content alignment problem

Here is the code that cause me problem since few hours: TabItem newTab = new TabItem(); newTab.Header = source.Name; newTab.Content = source.GetGui(); newTab.HorizontalContentAlignment = HorizontalAlignment.Stretch; newTab.VerticalContentAlignment = VerticalAlignment.Stretch; this.inputSou...

WPF MediaElement Freezing on last frame when setting Position

I have a MediaElement in WPF playing a WMV, that I'm rewinding 4 seconds (and I've also tried 4000 Milliseconds with same result). I want to simply loop the last 4 seconds of the video, so i'm .... protected override void videoBase_MediaEnded(object sender, RoutedEventArgs e) { //would reset to zero (replay) //base.MediaDisplayC...

VS 2010 Beta 1 doesn't recognize the System.Printing.PrintTicket class

I'm having the following problem using the Visual Studio 2010 Team System Beta 1: While working on some printing code, I tried to declare a variable of type System.Printing.PrintTicket, but Visual Studio doesn't seem to recognize that the class exists. It appears in the MSDN documentation, and other classes like System.Printing.PrintQue...