+1  A: 

My suggestion is to get rid of your MDX plugin.

I've used both WPF and MDX, though not in the same project. Both libraries talk to DirectX and ultimately will store state at the native level, which can cause problems. With WPF I've had rendering issues related to my video drivers and the fix was to upgrade the video driver to a newer version.

Initializing DirectX can affect the ways DirectX (and your CPU!) performs for your whole application . For example, when you initialize MDX by default it will set the CPU to do all floating point calculations in single precision, for the whole process, regardless of how you declare your original value. As you might imagine this lead to a lot of head scratching for a long time as to why we were getting different results in the application and our unit tests.

I suspect that when MDX is initializing it is enabling, or disabling some feature or setting in your graphics card (or possibly some software setting) that is affecting the WPF pipeline somehow.

I wish I could be more helpful. Good Luck.

Peter Tate
Thanks for writing, but I can't switch away from MDX right now. I would certainly like to in the future.
Jake Pearson
A: 

Have you tried SlimDX instead of MDX? SlimDX is a newer wrapper around DX and is actively under development. Perhaps you could do in SlimDX the same thing you use your MDX-Plugin for and the scrollbar functions normally again.

Peter is right about the interaction of WPF and MDX. WPF uses DirectX internally. So changing settings in MDX (or SlimDX) can change how WPF behaves. You could also try to take a look at the code of the WPF scrollbar (for example with the .NET Reflector, IDA, whatever you need) and check the settings the Scrollbar relies on.

Tobias Langner
A: 

I'd second the reservations of the previous posters regarding MDX in the context of WPF. One shot into the dark though:

Have you tried targeting your control for .NET Framework 3.5 SP1 already? There has been significant work regarding DirectX/Direct3D interoperability and performance, see for example:

Some of those enhancements might eventually yield positive side effects regarding your problem.

Steffen Opel
A: 

I took everyone's advice and ported my app to SlimDX. It wasn't too bad (almost every class/method/field is named exactly the same in SlimDX as MDX). Unfortunately, I still had the same issue. I was able to simplify Both SlimDX and MDX down to the following app:

public partial class MainForm : Form
{
 Direct3D Direct3D = new Direct3D();
 Panel slimPanel = new Panel();

 public MainForm()
 {
  InitializeComponent();

  CreateDevice();
  BuildWindows();
 }

 void BuildWindows()
 {
  var listBox = new System.Windows.Controls.ListBox();
  listBox.ItemsSource = Enumerable.Range(0, 100);
  var elementHost = new ElementHost();
  elementHost.Child = listBox;

  elementHost.Dock = DockStyle.Fill;
  Controls.Add(elementHost);
  slimPanel.Dock = DockStyle.Left;
  Controls.Add(slimPanel);
 }

 void CreateDevice()
 {
  PresentParameters presentParams = new PresentParameters();
  presentParams.BackBufferHeight = slimPanel.ClientRectangle.Height;
  presentParams.BackBufferWidth = slimPanel.ClientRectangle.Width;
  presentParams.DeviceWindowHandle = slimPanel.Handle;

  var device = new Device(Direct3D, 0, DeviceType.Hardware, slimPanel.Handle, CreateFlags.HardwareVertexProcessing, presentParams);
 }
}

The scroll bar won't show. I was able to get the scrollbar to show if I made sure the listbox got to paint before the Device was created.

The final solution was to add a WPF ListBox to my form in the constructor then delete it after the form finishes loading. I'm not sure if this is a bug in WPF or DirectX, I might try submitting a bug with Microsoft.

BTW, I can't get XNA to cause this issue.

Jake Pearson
A: 

Are you on Vista? We've seen a lot of SlimDX/WPF simply vanish by creating a Direct3D9Ex device instead of a normal one when running under Vista targets.

Promit
Pardon the noob question. How I do I know if I created a Direct3D9Ex versus a normal one?
Jake Pearson
My device is an instance of SlimDX.Direct3D9.Device. BTW, thanks for writing SlimDX!
Jake Pearson
+2  A: 

I've seen this bug too. It is not a SlimDX issue per se, but rather due to DirectX using 32-bit math on the x87 FP stack.

Use the FpuPreserve flag when initializing your device and the problem should go away.

mpg
+2  A: 

As it turns out, I stumbled on the solution today while working with a client. If you add the CreateFlags.FpuPreserve flag to your device creation, the scrollbar should go back to normal.

Promit