wpf

WPF : Adding Border to an image programmatically

I want to add a style to the the image programmatically. Here is my code <UserControl.Resources> <Style x:Name="BranchPages" x:Key="BranchPages"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Border BorderThickness="2" BorderBrush="Gr...

WPF Listbox.selecteditems returns items in the order they were selected

Hi, I was debugging a co-workers program and ran across this issue in WPF. It looks like the listBoxName.SelectedItems returns a list of selected items, in the order a user selects the item from the interface. This is a problem because I need to preserve the actual order the items. Example: the listbox is in Extended selectmode and ...

How to use XPSDocument to open a XPS file that is contained in a WPF application as a binary resource?

Hi folks, Basically I have embedded a xps file in a WPF application containing a XPSDocument Viewer as a resource. On loading the application, I just want the document viewer to display that embedded resource. public Page1() { InitializeComponent(); XpsDocument doc = new XpsDocument(SmartsysBrowser.Properties.Resources.test1, File...

wpf Interactivity.Behavior<T> vs attached properties

Hi, I'm trying to find some differences between these approaches. Is there any situation where behaviors are used and the same functionality could not be done with attached properties? ...

window singleton

Greetings, In our application user may click on item in datagrid and new window with list of companies is shown based on that item. Client wants this window to be non modal and if window is already opened and user clicks on different item in datagrid this window will be reloaded with new data from item in datagrid. How can we achieve it...

WPF: Prevent "Completed" event from firing after removing animation

How can I remove a running animation from a WPF element in such a way that its Completed event does not fire? The solutions presented here and here remove the animation's visible effects, but the Completed event still fires at the time that the animation would have completed. Here's some code that demonstrates my problem (it's in the ...

DrawingBrush used as the Fill for a Rectangle

I have the below definition for a DrawingBrush. It is an exmaple I found online that draws an arrow: <DrawingBrush x:Key="arrow" Stretch="Uniform"> <DrawingBrush.Drawing> <DrawingGroup> <DrawingGroup.Children> <GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M 358.447,332.449L 358.447,319.664L 380.875,319.664L 380.79...

WPF - Handle an ApplicationCommand in the ViewModel

I bet this has been answered many times over, but... For a simple situation where a button on a UserControl has its command property set to something like Find (ApplicationCommands.Find) how would the ViewModel handle that command? I usually see command handlers wired up with a CommandBinding that gets added to a CommandBindings collec...

CompositeCollection breaks ComboBox AutoComplete-Feature?

push Hello everybody! I'm using a WPF ComboBox with IsTextSearchEnabled="True" (Autocomplete) and want to bind its ItemsSource-Property to a CompositeCollection. Unfortunately, the Combobox doesn't seem to recognize the items provided by a CollectionContainer within the CompositeCollection. They are shown, but not selected by AutoCompl...

Bind SelectedValue to a WPF combobox

I've tried searching up and down for this but can't find anything. I have a combobox in a listview. The listview is bound to a list of objects exposed through the controller that the datacontext is bound to. One of the properties of the items in the list is a string. I'm trying to bind that value to what's in the combobox. Here is a...

WPF/Silverlight Conditional Styles

Given the object graph below I need to have 2 different style applied depending on whether the Parent object has any children or not. I am unsure how to go about setting the style on a condition like this, can anyone help please? Parent (Object) Prop1 (string) Prop2 (string) Children (List<Object>) Thanks in advance. ...

WPF: How do I prevent users from entering text in a Textbox data bound to a numeric property?

WPF: How do I prevent users from entering text in a Textbox data bound to a numeric property? ...

WPF DataGrid Columns not lining up with headers

My WPF DataGrid columns are not lining up with the headers. Any idea why? http://picasaweb.google.com/lh/photo/CahvlINknhL5ykIW2zCfIw?feat=directlink More Info: http://sweux.com/blogs/smoura/index.php/wpf/2009/04/27/wpf-toolkit-datagrid-part-ii-custom-styling/ ...

WPF: How do I get a reference to a styled window control in code behind?

I have a window defined with a style: <Window x:Class="winBorderless" x:Name="winBorderless" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Local="clr-namespace:WindowStyle" Style="{StaticResource Window_Cartesia}" ...

The calling thread must be STA, because many UI components require this.

I am using : http://www.codeproject.com/KB/IP/Facebook_API.aspx I am trying to call the xaml which is created using WPF. But it gives me a The calling thread must be STA, because many UI components require this. error I don't know what to do. I am trying to do this: FacebookApplication.FacebookFriendsList ffl = new FacebookFrie...

Basic class naming and visibility questions

I always see people giving me code (I mean code examples for questions on SO and the like) like: class MyData{ ObservableCollection<Color> Colors; ObservableCollection<Fruit> Fruits; ObservableCollection<Pairs> Pairs; public void MatchCurrentSelection(){ ..... etc } } }...

Sorting List vs. ObservableCollection

I have found out that I am "doing WPF wrong" and frustratingly must overhaul alot of my code. How could I convert the following: public static class SortName { public static int Compare(Person a, Person b) { return a.Name.CompareTo(b.Name); } } and I call it like: list.Sort(SortName.Comp...

Manipulating ObservableCollection vs Replacing a List

I have a backend Dictionary that is used for synchronization (ie. to both a filestore and a webservice). Off the top of this I need to generate lists/enumerables for the WPF frontend to consume. What is the difference between either hooking an enumerable up to the dictionary, and calling PropertyChanged when it is updated to using an Ob...

How can I loop through all of the controls in a tab control (wpf)?

I have seen a few examples of how to do this with winforms but have been unable to get it to work in wpf as a wpf TabItem does not have a definition for Controls. Here is the code that I'm using right now, which does not work. TabItem ti = rep1Tab; var controls = ti.Controls; foreach (var control in con...

WPF: Transfer non-freezable items from one Dispatcher to another

We load FixedPage objects from an XPS document, process and displays it.The following code does the loading of the FixedPage from a Package: FixedPage fp = null; Package package; // xps package Uri packageUri; // uri of the package in the package store Uri fixedPageUri; // uri of the fixed page ...