Wpf 位图的TreeView/ScrollView渲染错误?
有一个WPF(.NET 3.5)树视图,其中包含位图。 没什么特别的:Wpf 位图的TreeView/ScrollView渲染错误?,wpf,scroll,bitmap,treeview,Wpf,Scroll,Bitmap,Treeview,有一个WPF(.NET 3.5)树视图,其中包含位图。 没什么特别的: <ControlTemplate x:Key="ctrlOutputTree" TargetType="{x:Type vo:OutputTreeView}"> <TreeView x:Name="OutputTree" ItemContainerStyle="{DynamicResource TreeViewItemStyle}" KeyboardNavigation.
<ControlTemplate x:Key="ctrlOutputTree" TargetType="{x:Type vo:OutputTreeView}">
<TreeView x:Name="OutputTree" ItemContainerStyle="{DynamicResource TreeViewItemStyle}"
KeyboardNavigation.TabNavigation="Cycle" SnapsToDevicePixels="True" MouseDown="OutputTree_MouseDown"
Loaded="OutputTree_Loaded" RenderOptions.BitmapScalingMode="NearestNeighbor">
<TreeView.Resources>
<Style TargetType="TreeViewItem">
<EventSetter Event="RequestBringIntoView" Handler="OutputTree_RequestBringIntoView"/>
<Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" />
</Style>
</TreeView.Resources>
<TreeViewItem ItemsSource="{Binding Converter={StaticResource featureDiffsSourceCreator},Mode=OneWay}"
IsExpanded="True" Margin="0,4,0,0"
KeyDown="AttrDiffTreeviewItem_KeyDown">
</TreeViewItem>
</TreeView>
</ControlTemplate>
它显示得很好,但当我们滚动树时,有时位图会失真。大多接近底部。有时我们需要调整树的大小,但这迟早会发生
ItemX是文本,它旁边的表格是位图。
在这之后,当它出错时,如果我用滚动条位置拇指滚动树,只向上/向下滚动1个像素,它会再次变得清晰和良好。
但是如果我在滚动条上使用向上/向下箭头滚动,位图在几次单击后仍然无效(然后消失)
如果我在XAMLMultiBinding/imageConverter
-->中替换BitmapSource生成,我找到了一个解决方案。
不知道它为什么会起作用,但似乎解决了问题:
如果在imageConverter(在本机控件中)中,我返回BitmapImage^,而不是BitmapSource^,则没有问题。
非常奇怪,但我只是从BitmapSource创建BitmapImage,返回它,没有问题。
WPF太可怕了…我找到了解决方案。
不知道它为什么会起作用,但似乎解决了问题:
如果在imageConverter(在本机控件中)中,我返回BitmapImage^,而不是BitmapSource^,则没有问题。
非常奇怪,但我只是从BitmapSource创建BitmapImage,返回它,没有问题。
WPF太可怕了…只是为了好玩,试着用一个视图框看看。@AnjumSKhan你能提供更多细节吗,我应该在哪里使用它吗?顺便说一句,我用更多信息/示例/屏幕截图…
尝试了,同样的结果。。。同样,如果我在XAML
中直接指定位图而不是转换器,也可以。只是为了好玩,试着使用视图框看看。@AnjumSKhan你能给出更多细节吗,我应该在哪里使用它吗?顺便说一句,我用更多信息/示例/屏幕截图…
尝试了,同样的结果。。。同样,如果我直接在XAML
中指定位图,而不是在转换器中指定位图,就可以了。
<ControlTemplate x:Key="ImageTemplate">
<Image VerticalAlignment="Top" Margin="3,1,0,0"
RenderOptions.BitmapScalingMode="NearestNeighbor"
RenderOptions.EdgeMode="Aliased"
Stretch="None">
<Image.Source>
<!-- <BitmapImage UriSource="c:\\imageBMP_test.bmp" />-->
<MultiBinding Converter="{StaticResource imageConverter}">
<Binding Path=....
</MultiBinding>
</Image.Source>
</v:Image>
</ControlTemplate>
System::Drawing::Bitmap^ b = System::Drawing::Image::FromHbitmap((IntPtr)aBmp);
IntPtr hb = b->GetHbitmap();
System::Windows::Media::Imaging::BitmapSource^ bs =
System::Windows::Interop::Imaging::CreateBitmapSourceFromHBitmap(hb,
System::IntPtr::Zero,
Int32Rect(0,0,nWidth,nHeight),
BitmapSizeOptions::FromEmptyOptions());
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap("c:\\imageBMP24_96dpi_small.bmp");
IntPtr hb = b->GetHbitmap();
System::Windows::Media::Imaging::BitmapSource^ bs =
System::Windows::Interop::Imaging::CreateBitmapSourceFromHBitmap(hb,
System::IntPtr::Zero,
Int32Rect(0,0,nWidth,nHeight),
BitmapSizeOptions::FromEmptyOptions());