wpf

What causes a WPF ListCollectionView that uses custom sorting to re-sort its items?

Consider this code (type names genericised for the purposes of example): // Bound to ListBox.ItemsSource _items = new ObservableCollection<Item>(); // ...Items are added here ... // Specify custom IComparer for this collection view _itemsView = CollectionViewSource.GetDefaultView(_items) ((ListCollectionView)_itemsView).CustomSort = n...

How to get the brush used to create a FormattedText in WPF

I have a FormattedText object, like the one you'll normally pass to DrawingContext.DrawText Most of the time, I'll pass this object to DrawingContext.DrawText, but sometimes I'll need to render this text to a file format not supported by WPF. I know how to render the text to this file, what I don't know is how to get the brush that sho...

Recommended Prism v2 Silverlight/WPF Project Structure

I'm currently tasked with teaching all the developers, in the company I work in, about Silverlight (v2). The only problem is that I don't have any real Silverlight experience myself. Of course I've studied all the technical details about stuff like databinding, layout etc. so I can help my colleagues. But one thing that is hard to find a...

WPF/XAML Style set Property for child items?

Hello, I working on a XAML style for my controls. The code below is for setting the color of a stackpanel. It works fine but there is something else I want to do. If the trigger is activated I want to set the font color for all child items inside the stackpanel. At the moment I only have textblocks inside the stackpanel and I know I co...

WPF - How to combine DataTrigger and Trigger?

NOTE I have asked the related question: How to combine DataTrigger and EventTrigger? I have a list box containing several items. The item's class implements INotifyPropertyChanged and has a property IsAvailable. I use that property to indicate unavailable options in the list using a different colour. However, if a selected item i...

Custom WPF control for showing a Graph and highlighting Points of Interest.

Question for you all, I've been charged with developing an application to view data about a testing cycle we do for environmental screening, products are placed in an environmental control, freezing and heating the product while a variety of self-tests are run. My manager would like to see a graph of temperature over time as an x/y graph...

Making a WPF application retain focus at all times

Hello everyone, I've got an issue with a WPF app I'm writing. The application needs to be able to keep focus at all times. The computer it's running on is a highly specialized machine with the only purpose of running this application. There is no keyboard connected to the machine (it has a touch screen), so the only thing that can st...

WPF - ItemsControl - How do I get find my "CheckBox" item that is in the ItemTemplate?

I have the following (very simple) ItemsControl: <ItemsControl Name="BlahList" ItemsSource="{Binding Blah}"> <ItemsControl.ItemTemplate> <DataTemplate> <CheckBox Name="MyCheckBox" Content="{Binding Text}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> In code, I would like to do the following: ...

WPF ListBox ListCollectionView anonymous type navigation problem

Example of problem: Framework: WPF Visual control: DataGrid from CodePlex public Window() { InitializeComponent(); var listView = new ListCollectionView( new[] { new { Bool = false, Str = "Value1" }, new { Bool = false, Str = "Value1" }...

How can I easily revert changes on a DataBound form?

If I have a form with controls DataBound to an instance variable object, is there a way to do revert changes that the user made, possibly by doing something like: myLocalObject = DataLayer.GetCurrentState(); and have the form's controls (bound to myLocalObject) automatically pick up the changes? Thanks! ...

How do I bind my controls in a WPF DataGridTemplateColumn to a DataTable?

I have a DataGrid bound to a DataTable that I want to make custom columns for using a DataGridTemplateColumn, but I'm not sure how to reference the value in the cells of the DataTable. Every example I see online either binds the DataTable and doesn't change the templates, or uses a custom object and references the properties of the bound...

WPF: Allow TextBox to be resized but not to grow on user input

I have a TextBox defined inside a window like so: <Window x:Class="NS.MainWindow" ... SizeToContent="WidthAndHeight"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="100" /> <ColumnDefinition MinWidth="200" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> ...

Set focus in WPF textbox

I am writing a control in WPF that draws a shape on a form and then draws dimensions of this shape. These dimensions are editable so they are shown in a text box. When the user changes a dimension in a text box the shape is updated. I am updating the shape when the textbox showing the dimension loses focus i.e. as soon as the text box ...

Referencing controls in a WPF DataTemplate

In a WPF page that I'm designing for my church, I have two ListBox controls bound to the results of two Linq-to-Entities queries: the first listbox/query contains all the folks who haven't yet pledged for the year, the second listbox/query contains all the folks who have pledged (and their associated pledges). Specifically: var familie...

Listbox item foreground problem

I am facing a problem with one of my XBAP (WPF Browser application) projects: Here I have two list boxes: One a simple list containing text content Second one containing an expander as each item: Now when I click on the item in the first listbox (on the left side), the foreground changes to white and then changes back to black if ...

Databinding items to Canvas

I have a userControl that contains a canvas. I would like to databind items to it so they are positioned automagically. Here's a great example that shows how to databind items on a canvas, but I want it to work on my specific userControl. (I believe it's not possible to specify a userControl in a ItemsPanelTemplate) ...

How to bind to Popup.IsOpen to Validation.HasError in code

I have a Textbox which is bound to my data object. If the validation fails I would like to show a popup which contains the error message. In XAML this works fine. I'm using the following XAML: <TextBox Height="23" Margin="54,12,104,0" Name="textBox1" VerticalAlignment="Top" Text="{Binding Value, ValidatesOnExceptions=True, UpdateSource...

Shutting down a WPF application from App.xaml.cs

I am currently writing a WPF application which does command-line argument handling in App.xaml.cs (which is necessary because the Startup event seems to be the recommended way of getting at those arguments). Based on the arguments I want to exit the program at that point already which, as far as I know, should be done in WPF with Applica...

Getting non-UI objects to respond to WPF command bindings

I have a ViewModel class which i want to respond to the built in Refresh command whic is fired from a button but i'm not sure how to declare the CommandTarget. Briefly, my code is as below The ViewModel constructor and CanExecute and Executed event handlers - public ViewModel() { CommandBinding binding = new CommandBi...

How can I change the color of the gridlines of a Grid in WPF?

I have a Grid (not a DataGrid, but a real Grid), with GridLines set to True. How can I change the color of the gridlines? Hardcoded in XAML is ok, since it is just for development-reasons. <Grid ShowGridLines="True" /> ...