wpf

Why do I get an 'InvalidCastException'

private Incident incident = null; incident = (Incident)(rdc.Incidents.Where(i => i.ID == ID)); I get the following exception: Unable to cast object of type 'System.Data.Linq.DataQuery`1[WPF.Incident]' to type 'WPF.Incident'. I need an instance of Incident to use it like this: IList listInjury = ((IListSource)incident.Incident_Injur...

How to use a defined brush resource in XAML, from C#

So far I have this <UserControl.Resource> <LinearGradientBrush x:Key="KeyDownBrush" .....> Now I would like to access this defined resource when a key is pressed and replace the current objects fill with the KeyDownBrush, in C#. I've tried this.Resource.Contains("KeyDownPress") and have been able to get True returned so I presume I ...

What is the simplest method to change the desktop with one click

I have a window with WindowStyle="none" and WindowState=Maximized" and now I'd like in my contextmenu set the MenuItem to switch the application to the other desktop. whats the simplest way to do that? ...

C# WPF datagrid: Column count always equal to 0

I have created a WPF tooklit datagrid in C# and the ItemsSource is set in the XAML. The columns are automatically generated. I am trying to do a datagrid that uses an ObservableCollection, pretty much like what is on this website. At the bottom you will find a sample that you can download (here is the link) My problem is that I'm try...

Sorting in window datacontext in WPF

Another question related to this one. I have a List that is the datacontext of my MainWindow. I use that list to populate a ListBox and a ComboBox. When I sort the items, both the ComboBox and the ListView get updated all right. But now I need the combobox to be sorted in a different way than the ListView. I. E. If the object were a Pe...

YouTube XL in WPF WebBrowser?

I'm trying to create a simple HTPC interface and found YouTube XL (http://youtube.com/xl) which i thought would be cool and easy to add to my program. I'm using WPF so i simply tried to add a System.Windows.Controls.WebBrowser and navigate to that adress. The problem is that there is no video, everything else around the actual video wo...

Removing WPF ListView/GridView highlight chrome

I have WPF ListView with GridView view and I want to remove any trace of row highlight. This useful piece of code can be found in one answer on this site: <ListView.ItemContainerStyle> <Style TargetType="{x:Type ListViewItem}"> <Setter Property="Control.Focusable" Value="False"/> <Style.Triggers> ...

Superscript / subscript in hyperlink in WPF

I'm trying to make a Hyperlink that contains text with super- and/or subscripts. I've found two ways to do this, and both of them suck. Solution #1: use Typography.Variants. This gives a terrific superscript... for some fonts. <StackPanel> <TextBlock FontFamily="Palatino Linotype" FontSize="30"> <Hyperlink>R<Run Typography.Varian...

Detect whether a font supports variants (like superscript and subscript)

WPF has the Typography.Variants attached property that lets you do superscript and subscript. However, it only works for some fonts. For other fonts, the variant is utterly ignored, and the text is shown normally. (Code sample and screenshot here) Since it silently falls back to a no-op, I have no idea that anything went wrong; but my u...

Can I use XamlReader.Load or InitializeFromXaml from a WPF Window, for the Window definition?

I want to produce some library code that will be included into WPF applications. The library may pop up a Window, depending on circumstances. I can define the Window in XAML, but I'd like to treat the XAML as a template. At runtime, at the time the Window is being created so that it can be displayed, I want to replace certain tags in t...

Is it possible to apply Blend behavior using style or template?

I'm very happy with my small collection of Blend behaviors, actions and triggers - they are easy to use and powerful. But I still can't figure out how to avoid applying them on per element basis. For example, if I have a behavior as such: <Rectangle> <i:Interaction.Behaviors> <il:MouseDragElementBehavior/> </i:Interactio...

Making part of a FlowDocument non-selectable

I want to make a FlowDocument that contains both user-specified content, and hyperlinks for manipulating that content. I want the user to be able to highlight the content with the mouse, and copy it to the clipboard. Is there any way to allow that, while preventing the user from highlighting and copying the hyperlinks? (Note that the us...

WPF window resizing - no preview / show rubber band

Is there a way to force a WPF window to use a rubber band (no live preview of contents during resize) when resizing? I realize this is usually a user preference on Windows but my application uses D3D windows and there is significant flicker when resizing (particularly from the top left corner outward). -- I should have mentioned I am ...

Learning WPF at work

There are some projects that could use WPF at work, for the sake of adopting new technologies. But the problem is, I can't jump start WPF easily. I recognize the learning curve is steeper than Winforms. Though even with Winforms one can start doing UIs and programmatically customize them in a day. So the problem is: I don't have any ...

D3DImage using DX10

Is it possible to use DirectX 10 (I am using SlimDX) with WPF's D3DImage? The only examples and docs I can find only show using DX9 surfaces. ...

Changing Hyperlink foreground without losing hover color

I'm writing a WPF app, and I want some of my hyperlinks to be the default blue, and others to be green. No problem -- I can just set Foreground: <TextBlock><Hyperlink Foreground="#0C0">Mark as done</Hyperlink></TextBlock> The trouble is, when I do this, the hover effect goes away. In a normal Hyperlink, when I move the mouse over the ...

UserControl with Exposable Command on WPF

Hi, I'm creating a Toolbar with some buttons, and I want each button to execute an different command according to the ViewModel attached to it's DataContext, so I created if like this: public readonly DependencyProperty NewCommandProperty = DependencyProperty.Register( "NewCommand", typeof(ICommand), typeof(VirtueGridToolbar)); ...

Get current CPU, RAM and Disk drive usage in C#

How to get the CPU, RAM and Disk drive usage of the system in C# code? ...

Tool to simulate WPF user control?

I just wan to know if there are any tools to simulate user control without integrating it to the actual application. I need it just to test the user control's logic and functionality without depending on the whole application itself. ...

Adding Grid and Controls dynamically in WPF.

I am now doing an application that shows the HDD usage in the system. For that I want to generate the grid and the controls (like progress bar and labels) dynamically to show the usage. Is there any XAML template available for this purpose? ...