wpf

How to set width to 100% in WPF

Is there any way how to tell component in WPF to take 100% of available space? Like width: 100%; in CSS I've got this XAML, and I don't know how to force Grid to take 100% width. <ListBox Name="lstConnections"> <ListBox.ItemTemplate> <DataTemplate> <Grid Background="LightPink"> <Grid.Co...

Forcing code execution on main thread.

How can I force a section of code to be executed on my main thread? This is why I'd like to know: I have a custom created message box that at times gets shown from a thread that is not the main thread. However, when the message box constructor is called I get an InvalidOperationException saying "The calling thread must be STA, because...

WPF ObjectDataProvider with Mouse.GetPosition()

I have the following code, dw:ObjectReference is an implementation which is supposed to point to a declared ViewPort3D not in the UserControl.Resources. Is this even possible? And if so what should I replace dw:ObjectReference with? <ObjectDataProvider MethodName="GetPosition" ObjectType="{x:Type Mouse}" x:Key="odp"> <ObjectData...

WPF Client communicating with WCF Windows Service over Network, Feasible?

At work, I want to create a WCF Windows Service that runs on a network server. Then I want to create a WPF application that can be installed on various machines on the network. This WPF application needs to be able to communicate with the WCF Windows Service on the network server. Is this feasible? Is there a better way to accomplish w...

WPF integrating with web cam

How do you integrate a PictureBox to display a video through WPF? ...

WPF integrating with a web cam and rotating the video

is this possible? ...

How to override application styles in a wpf control created at runtime

I am trying to create a WPF control at runtime, but I can't figure out how to make it ignore the styles coming from the App.xml resources. I've tried setting the style to null and the OverridesDefaultStyle to true but no luck. The app settings set the foreground to white, and I can't seem to explicity set it to anything else. ...

Application that works in both SQL Server And Oracle Databases

What is the best approach to build a small (but scalable) application that works with Sql Server or Oracle? I'm interested in build apps that supports multiple databases, in the process behind the feature. ...

WPF: Basic question about Dependency Properties

I have the following Xaml in a Window (ArtistInfo): <Grid> <TextBlock Text="{Binding Artist.Name}"></TextBlock> </Grid> And this is the code-behind for the same window (code simplified for question's sake): public static readonly DependencyProperty ArtistProperty = DependencyProperty.Register("Artist", typeof(Artist), ty...

WPF: Having hardcoded text with a binding in a TextBlock

In WPF, is there any way to have the Text property of a TextBlock to contain both hard coded text and a specific binding? What I have in mind is something along the lines of the following (ofcourse, the below doesn't compile): <TextBlock Text="Number of Fans: {Binding Artist.Fans.Count}"></TextBlock> ...

WPF Color interpolation

Hello, I am trying to paint a WPF control's background based on a palette where each color has been assigned with values (e.g. Red = 0, DarkGreen = 10, Green = 20,LightGreen =30) and a user-selected value (e.g. 25) that would give the resulting color. I would like the resulting color to be an interpolation between the 2 nearest color va...

Selecting DataTemplate based on sub-object type

I want to databind an ItemsCollection, but instead of rendering the collection items, I want to render sub-objects reached via a property on the collection item. To be more specific: this will be a 2D map viewer for a game (though in its current state it isn't 2D yet). I databind an ItemsControl to an ObservableCollection<Square>, where...

Can you use ValidationRules on ListBox.SelectedItems?

I want to use ValidationRules to verify that a few ListBox controls have at least one item selected. I tried doing it this way: <ListBox ItemsSource="{Binding Path=AvailableItems}" Behaviors:MultiSelectorBehaviours.SynchronizedSelectedItems="{Binding ChosenItems}" x:Name="ListBoxItems"> <ListBox.Tag> <B...

Animating removed item in Listbox

I have some Listboxes in my app bound to ObservableCollections, and i would like to animate an item if it's being removed. I already found a question about animating added items by using the FrameworkElement.Loaded event, but of course that doesn't work the same way with the Unloaded event. Is there any way to do this in a way that ca...

WPF custom error-handling dialog box?

I am trying to set up my WPF application so that when an exception goes unhandled, an error dialog pops up. In good ol' WinForms this was possible by adding Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); To your Program.cs file and then showing whatever dialog you wanted i...

Set system focus on my application

I have an application that will mainly operate in the background. I want certain system events that it handles to cause the app to steal focus from the foreground app, whatever that is. But UIElement.Focus() seems to only set the focus within the WPF app. That is, if the WPF app already has the focus as a whole, then Focus() sets the ...

What is WPF for the WinForms programmer?

What is WPF to the WinForms programmer? WinForms distilled is adding controls to forms, and adding event handlers. This is simple and easy and allows you to make functional GUIs quickly. WPF on the other hand is XAML (?) + Code (?) that seems like a much more complicated way to make prettier UIs slowly. There are plenty of existing S...

How to bind ControlTemplate Enabled property to Opacity in WPF XAML

In WPF inside XAML how to extend a ControlTemplate as such that when applied to a button and the button gets disabled it fades to 0.5 opacity while disabled and once enabled fades back to 1.0 opacity. This visual effect should work also when a parent is being disabled. ...

[WPF] Testing the scrollbar visibility of a ListBox in code-behind

How to check whether the vertical scrollbar of the listbox is visible in code-behind? I have a listbox with x:Name="listOfItems" and its underlying ScrollViewer's VerticalScrollbarVisibility is set to auto. When the ItemsSource property of the ListBox is set, I want to check whether the verticalScrollbar is visible, but I don't know wh...

How to force ListBox to reload properties of ListBoxItems

Is there any way, how to force ObservableCollection to fire CollectionChanged? I have a ObservableCollection of objects ListBox item source, so every time I add/remove item to collection, ListBox changes accordingly, but when I change properties of some objects in collection, ListBox still renders the old values. Even if I do modify so...