wpf

SourceName with MultiTriggers

Is it possible to use a multiTrigger to evaluate properties on multiple elements? That don't reside within a template, but are within the Usercontrol/Window. Example: <CheckBox x:Name="checkBox1" /> <CheckBox x:Name="checkBox2" /> <CustomControl> <CustomControl.ContentTemplate> <DataTemplate> ...

Creating a WPF Window from a WinForms BackgroundWorker

I have a WPF dll that contains a number of Window classes and exposes methods that display those windows. I also have a separate WinForms project that is calling one of those methods in the WPF project inside the DoWork method of a BackgroundWorker component. On the line of code that instantiates a WPF Window, I get the following runti...

How can I programmatically scroll a WPF listview?

Is it possible to programmatically scroll a WPF listview? I know winforms doesn't do it, right? I am talking about say scrolling 50 units up or down, etc. Not scrolling an entire item height at once. ...

WPF - Left align items in an itemspresenter?

I've got this bit of code in one of my control templates for a SplitButton I'm working on: <Popup x:Name="PART_Popup" AllowsTransparency="True" Grid.Row="1" IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" Placement="Bottom" PopupAnimation="{DynamicRe...

Passing origin of ContextMenu into WPF Command

Interesting problem related to firing commands from context menu items... I want to fire a command to insert a row in my control, InsertRowCmd. This command needs to know where to insert the row. I could use Mouse.GetPosition(), but that would get me the position of the mouse currently, which would be over the menu item. I want to get...

Help "?" button

How can add this button to the title bar in WPF, by it being so used in a lot of applications I thought it would be built in or something, but looks like it isn't. Anyway let me know if you know anything about this. Thanks. Edit: Isn't there anything equivalent to this? Basically, to have the ? icon in win forms, all you need to do i...

C# EventHandler Beautiful Code (How To?)

Hi, I admit, it is kind of tiny, but I am looking for better ways to do the following code blocks. They should be self explaining... private void listBoxItem_PreviewMouseDown(object sender, MouseButtonEventArgs e) { var listBoxItem = sender as ListBoxItem; if (listBoxItem != null) { var clickO...

WPF "hex grid" component

Jumping into the world of WPF custom controls, and was wondering what the best way to design a HexGrid control would be? Think your favorite table-top war game; or, equally likely, your favorite video game that steals the design from a proud history of table-top war games. The underlying model exposes one significant method, as a part ...

Checkboxes not updating as expected

I have a listbox bound to a list of business objects. The items in the listbox are formatted using an itemtemplate. The itemtemplate includes a checkbox bound to a boolean property of the business object. When I spin up the app, the bool prop on the object in the list is changed when I click the checkbox. so far, so good. The dialog has...

How do get menu to open to the left in WPF?

I have a menu (with menuitems) in WPF. Unfortunately when I click on the menu heading it opens the menu to the right. The problem is that there is stuff on the right that I don't want it to overlap. How do I tell WPF to open the menu to the left? Do I need to do a control template? (control templates seem so heavy handed for such bas...

WPF PixelShaders: How to create a Temporary Register dependency property?

Hi, I've run out of the 8 possible constant registers in a wpf pixelshader effect. I need access to temporary registers, which I believe are available 6 on a DX 8.1 level gfx cards. Question is: How to create a temporary register dependency property in C# code? Constant registers are created like this: public static readonly Depende...

What is the easiest way to handle SelectedItem event with MVVM?

In the code below, when user selects Customer in the combobox, the customer's name is displayed in a textbox. I fill the Combox box with an ObservableCollection property on my ViewModel but how do I handle the SelectedItem event in my ViewModel? It's easy to implement this with code-behind as shown below, but how do I do this with the ...

WPF ItemsControl: Route TextChanged Event to all UserControl Items

Hello, I've placed in a ItemsControl Container (Template Stackpanel) my UserControls, which get dynamically added and removed while running the application. How can I route an Event (e.g. TextChanged or GotFocus) trough all elements in my UserControl (consists mainly of TextBoxes)? Is this where I should use "Delegates" or ICommand? I'm...

How can I get StackPanel to use an ItemTemplate?

In the following code, I tell the ComboBox to use the DataTemplate called CustomerTemplate by assigning its ItemTemplate attribute. StackPanel, however, doesn't have an ItemTemplate attribute. How can I get the StackPanel to also use CustomerTemplate? <Window.Resources> <DataTemplate x:Key="CustomerTemplate"> <StackPanel O...

How can I get a StackPanel to be only as wide as its content?

The following template shows dynamic information in a colored box. However, the box is always the full width of the DockPanel/screen. I could put a fixed Width in the Border element, but then a very long customer name might get cut off. How can I tell the Border that it should expand and contract its width based on width of its conten...

Sizing customized button to size of content

Hi, I've created the following very simple button style: <ControlTemplate x:Key="SimpleButton" TargetType="{x:Type ButtonBase}"> <ContentPresenter x:Name="content" HorizontalAlignment="Center" VerticalAlignment="Center" /> <ControlTemplate.Triggers> <Trigger Property="IsPressed" Value="True"> <Setter Propert...

How to get RadioButtons to work like ComboBox in MVVM pattern?

In the following code, the user selects a customer from the ComboBox and that customer's information is displayed in the box. Now I also want to get RadioButtons to work with the same functionality. I've got the RadioButtons to display the ObservableCollection of Customers, but how can I get the IsChecked to work, i.e. what is the equi...

How to limit dropdown height for combo box in XAML

What should i do if I want to limit the dropdown height of my combo box to 7? MaxDropdownHeight produces different results for different OS (Operating System); In XP for instance, if I set MaxdropDownHeight to 98, I get desired result, but when I try to test in Vista, its different. How shall I do this when using ComboBox in System.Windo...

How to get number of items in ObservableCollection from XAML?

I'm displaying all of my customers which I get from a ViewModel ObservableCollectoin property within a ComboBox like this: <ComboBox ItemsSource="{Binding Customers}" ItemTemplate="{StaticResource CustomerComboBoxTemplate}" Margin="20" HorizontalAlignment="Left" SelectedItem="{Binding SelectedCustomer, Mode=TwoWay}"...

WPF, MVVM, and Menu Foreground Color - Oh My.

I'm new to both WPF and MVVM. I searched for a good way to dynamically create menus in the MVVM partern and, not finding anything to my liking, rolled my own solution. It works, but for some reason the Foreground (text) color of the menus is sometimes (just sometimes) not correct. I was going to include a picture to demonstrate my pro...