很多个偶然因素导致的一个待解释的bug

最近用WPF开发绘图类程序,借鉴了http://www.codeproject.com/Articles/22776/WPF-DrawTools的WPF-DrawTools程序,此程序在本地运行一切正常,远程连接此电脑运行程序时,绘制图形会导致程序异常退出。

程序的Undo/Redo按钮采用了图片,禁用按钮时会触发Trigger将图片进行模糊处理。具体XAML代码见下面:
 (effects命名空间为xmlns:effects="clr-namespace:System.Windows.Media.Effects;assembly=presentationcore")

<Window.Resources>

<effects:BlurBitmapEffect x:Key="bmpEffect" KernelType="Box" Radius="2"/>
        <Style x:Key="toolbarImageStyle" TargetType="Image">
            <Style.Triggers>
                <DataTrigger Value="False"
                    Binding="{Binding
                        Path=IsEnabled,
                        RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}, AncestorLevel=1}}"

      >
                    <Setter Property="Image.BitmapEffect" Value="{StaticResource bmpEffect}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

</Window.Resources>

Undo/Redo按钮使用以上方式为

      <Button Name="undo" ToolTip="Undo"
                        Command="{Binding EditUndoCommand}"
                        IsEnabled="{Binding ElementName=drawingCanvas, Path=CanUndo, Mode=OneWay}">
                    <Image Source="Resources/Images/Edit_UndoHS.png"
                           Style="{StaticResource toolbarImageStyle}"/>
                </Button>
                <Button Name="redo" ToolTip="Redo"
                        Command="{Binding EditRedoCommand}"
                        IsEnabled="{Binding ElementName=drawingCanvas, Path=CanRedo, Mode=OneWay}">
                    <Image Source="Resources/Images/Edit_RedoHS.png"
                           Style="{StaticResource toolbarImageStyle}"/>
                </Button>

最终发现问题原因真是令人哭笑不得,匪夷所思,以上模糊半径为2时,程序会异常退出。模糊半径改为非2的数字例如2.1,1.8,5等,程序则完全正常。

这得是多少个巧合才能遇到的bug啊!求大牛指点!

 

posted @ 2013-04-13 18:56  tsingfei  阅读(190)  评论(0编辑  收藏  举报