开发者

WPF: Textbox scrollbar has no thumb

My textbox is the only control on a window, which is a part of a bigger application. The textbox contains a certain amount of text, large enough to show vertical scrollbar. The scrollbar appears, but without a thumb:

WPF: Textbox scrollbar has no thumb

I can still scroll the contents, either with mouse wheel or by clicking the arrow-buttons repeatedly. When I create a new project with the same window and textbox the scrollbar works as it should. The same happens with a WrapPanel. Do you have ideas what could be spoiling my existing project and causing this issue? In generic.xaml I found some styles overriding the defaults for scrollbar and scrollviewer, but even totally clearing generic.xaml didn't help.

Thanks in advance!

EDIT: right, the code. It's XAML only (no c# backing code).

<Window x:Class="TextBoxTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" MaxHeight="200" MaxWidth="200">
<TextBox x:Name="textbox" MaxLines="2"  MaxHeight="50" VerticalScrollBarVisibility="Auto" TextWrapping="WrapWithOverflow">
    Useless text..... asdasdasda ssssssssssssss ssss开发者_StackOverflowsss ssssaokdoka sdojwoandowm nxaofwha398ua ozmca3u0a3j3   a80a9fu 03 u0sf u0s9jf4s 0cuj wuf0j w40 fcjw cujwfj9 c9 u49 wsuc j9w3
    3089w 9f8u4wfv 0sf ufw0u w0fuw0 fwu f0uw 09djcazp zopf h43 wofh FYHFWFH WOWY HWO H wohg fujg 4g fugj 4 g0 4
    4w fw4 f3f g555u45y 55 some more some moresome more some moresome more some moresome more some moresome more some more.
</TextBox>
</Window>


The answer is astonishing!

Just after I'd started to suspect it might be a WPF bug, I found this forum thread. Guy who asked the question says: "My application uses a directx renderer from a DLL that's written in C++". Mine does almost the same with the difference that my renderer is written in C# (MDX) and uses D3DImage interop.

Following steps mentioned in the thread above, I moved DirectX initialization from OnInitialize() to Loaded event callback of the main window and now scrollbars regained their expected appearance. It seems that GUI must be displayed first, before the renderer is initialized.

So I guess it's reasonable to talk about a bug in this case.


It seems like a style problem. Remove explicit style setter from the TextBox (check both XAML and code behind). If TextBox has no explicit style, search for implicit styles (defined via TargetType="TextBox" or TargetType="{x:Type TextBox}" and/or x:Key="{x:Type TextBox"}).

Try snooping your application and check ScrollViewer's visual tree. It may give you some insights where to look.

Hope this helps.


At a guess: your TextBox is inside a StackPanel. If you want more than a guess, you'll need to provide code.


You can solve the problem adding CreateFlags.FpuPreserve during the creation of your D3D Device

Example:

this.device = new Device(0, DeviceType.Hardware, this.handle,
    CreateFlags.HardwareVertexProcessing |
    CreateFlags.PureDevice |
    CreateFlags.FpuPreserve, this.pparams);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜