简体   繁体   中英

WPF window shows blank

Excel AddIn, c#, .net 4.0, windows 7, ribbon my addin has a ribbon tab, several ribbon buttons, when one ribbon is clicked, the addin will send several web service calls and a window will pop up providing data in tab, treeview, gridview etc. data in treeview, gridview are populated from web service calls. All worked for a particular end user until yesterday When he clicked button, the window seems showing up, but it is kind of behind Excel and could not be focused. Also it is blank with no tab, treeview, gridview, etc. I verified all web service calls return properly. The user has windows 7, Excel 2010 (32 bit). I have no idea what could cause this. Please help. this is my WPF window. thanks

<Window x:Class="MIMICWPFLib.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:sharedC="clr-namespace:MIMICShared.Converter;assembly=MstarCommodityShared" 
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" 
    xmlns:dxt="clr-namespace:DevExpress.Xpf.Utils.Themes;assembly=DevExpress.Xpf.Core.v11.2"
    xmlns:Controls="clr-namespace:MIMICWPFLib.Controls"
    Title="{Binding Title}"        
Height="600" Width="850" Top="223" Left="164" ResizeMode="CanResize" Closing="WindowClosing"
WindowStyle="ToolWindow">
<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="MainWindowResources.xaml" />
            <ResourceDictionary Source="Controls/BizzySpinner.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <sharedC:BooleanToHiddenVisibility x:Key="boolToVis"/>
        <sharedC:NegativeBooleanToHiddenVisibiltyConverter x:Key="negativeBoolToVis" />
        <DataTemplate x:Key="{dxt:DXTabControlThemeKey ResourceKey=BackgroundTemplate, ThemeName=Office2007Silver}">
            <Border BorderBrush="#FF828790" BorderThickness="1" Background="#E5E3E3"/>
        </DataTemplate>
        <DataTemplate x:Key="{dxt:DXTabControlThemeKey ResourceKey=BackgroundTemplate}">
            <Border BorderBrush="#FF828790" BorderThickness="1" Background="White"/>
        </DataTemplate>
        <ControlTemplate x:Key="{dxt:DXTabControlThemeKey ResourceKey=TopLayoutTemplate}" TargetType="{x:Type dx:DXTabControl}">
            <Grid>
                <KeyboardNavigation.TabNavigation>Local</KeyboardNavigation.TabNavigation>

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" Margin="0,2,0,0" x:Name="tabHeadersPanel">
                    <KeyboardNavigation.TabIndex>1</KeyboardNavigation.TabIndex>
                    <KeyboardNavigation.DirectionalNavigation>Cycle</KeyboardNavigation.DirectionalNavigation>
                    <KeyboardNavigation.TabNavigation>Once</KeyboardNavigation.TabNavigation>
                    <Panel.ZIndex>1</Panel.ZIndex>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <dx:ClippedContainer Grid.Column="0" UseLayoutRounding="{TemplateBinding UseLayoutRounding}"
                                 Style="{DynamicResource {dxt:DXTabControlInternalThemeKey ResourceKey=ClippedContainerTopLayoutStyle}}">
                        <dx:TabPanelContainer x:Name="panelContainer" Style="{DynamicResource {dxt:DXTabControlInternalThemeKey ResourceKey=PanelContainerTopLayoutStyle}}">
                            <dx:TabPanelContainer.Resources>
                                <Storyboard x:Key="ScrollStoryboard">
                                    <DoubleAnimation Storyboard.TargetName="ItemsPanelTranslate" 
                                         Storyboard.TargetProperty="X" Duration="0:0:0.4" To="0">
                                        <DoubleAnimation.EasingFunction>
                                            <ExponentialEase EasingMode="EaseOut" Exponent="0" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </dx:TabPanelContainer.Resources>
                            <ItemsPresenter>
                                <ItemsPresenter.RenderTransform>
                                    <TranslateTransform x:Name="ItemsPanelTranslate" />
                                </ItemsPresenter.RenderTransform>
                            </ItemsPresenter>
                        </dx:TabPanelContainer>
                    </dx:ClippedContainer>
                    <dx:TabControlScrollButton x:Name="PrevButton" Grid.Column="1" Style="{DynamicResource {dxt:DXTabControlThemeKey ResourceKey=PrevButtonStyle}}" 
                                       Margin="{DynamicResource {dxt:DXTabControlInternalThemeKey ResourceKey=ComponentsSpaceForHorizontalLayouts}}" />
                    <dx:TabControlScrollButton x:Name="NextButton" Grid.Column="2" Style="{DynamicResource {dxt:DXTabControlThemeKey ResourceKey=NextButtonStyle}}" 
                                       Margin="{DynamicResource {dxt:DXTabControlInternalThemeKey ResourceKey=ComponentsSpaceForHorizontalLayouts}}" />
                    <!--<dx:HeaderMenu Grid.Column="3" x:Name="HeaderMenu" IsTabStop="False" Style="{DynamicResource {dxt:DXTabControlThemeKey ResourceKey=HeaderMenuStyle}}" 
                           Margin="{DynamicResource {dxt:DXTabControlInternalThemeKey ResourceKey=ComponentsSpaceForHorizontalLayouts}}" />-->
                    <Controls:HeaderMenuForDXTabControl Grid.Column="3" 
                                    x:Name="HeaderMenu"
                                    IsTabStop="False" 
                                    Style="{DynamicResource {dxt:DXTabControlThemeKey ResourceKey=HeaderMenuStyle}}" 
                                    Margin="{DynamicResource {dxt:DXTabControlInternalThemeKey ResourceKey=ComponentsSpaceForHorizontalLayouts}}" />
                </Grid>
                <Grid Grid.Row="1">
                    <dx:DXContentPresenter  ContentTemplate="{DynamicResource {dxt:DXTabControlThemeKey ResourceKey=BackgroundTemplate}}" IsTabStop="False">

                    </dx:DXContentPresenter>
                    <Grid Margin="1">
                        <dx:DXContentPresenter x:Name="contentPresenter" Margin="{TemplateBinding Padding}" UseLayoutRounding="{TemplateBinding UseLayoutRounding}"
                                   Content="{TemplateBinding SelectedItemContent}" ContentTemplate="{TemplateBinding SelectedItemContentTemplate}">

                            <KeyboardNavigation.TabNavigation>Local</KeyboardNavigation.TabNavigation>
                            <KeyboardNavigation.DirectionalNavigation>Contained</KeyboardNavigation.DirectionalNavigation>
                            <KeyboardNavigation.TabIndex>2</KeyboardNavigation.TabIndex>

                        </dx:DXContentPresenter>
                        <dx:TabControlFastRenderPanel x:Name="fastRenderPanel" Margin="{TemplateBinding Padding}" UseLayoutRounding="{TemplateBinding UseLayoutRounding}" Visibility="Collapsed">

                            <KeyboardNavigation.TabNavigation>Local</KeyboardNavigation.TabNavigation>
                            <KeyboardNavigation.DirectionalNavigation>Contained</KeyboardNavigation.DirectionalNavigation>
                            <KeyboardNavigation.TabIndex>2</KeyboardNavigation.TabIndex>

                        </dx:TabControlFastRenderPanel>
                    </Grid>
                </Grid>
            </Grid>
        </ControlTemplate>
    </ResourceDictionary>        
</Window.Resources>
<Grid>
    <Grid Visibility="{Binding ShowProgress, Converter={StaticResource negativeBoolToVis}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" ></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>                
        </Grid.RowDefinitions>            
        <Grid Grid.Row="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" MinHeight="65"></RowDefinition>                
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="Auto" MinWidth="2"></ColumnDefinition>               
        </Grid.ColumnDefinitions>

            <Image Grid.Row ="0" Height="37" Width="174" Margin="11,6,0,0" 
                   Name="image1" Stretch="Fill" VerticalAlignment="Top" 
                   HorizontalAlignment="Left" 
                   Source="/MstarCommodityWPFLib;component/Resources/MorningstarLogo_Red.gif" />

            <Border  Grid.ColumnSpan="1" Grid.Row="0" HorizontalAlignment="Right" Margin="0,10,0,0" 
                     Height="50" Width="400" Background="white" BorderThickness="1" BorderBrush="White"  >
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="23"/>
                        <RowDefinition Height="4"/>
                        <RowDefinition Height="23"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                    <ContentControl Content="{Binding Path=SearchBox}" Margin="0 0 5 0" />
                    <TextBlock Grid.Row="0" Grid.Column="1"> 
                    <Hyperlink Click="ShowSettings" TextDecorations="None">
                        <Image Source="{Binding ConfigImageFilePath}"  ></Image>
                    </Hyperlink>
                    </TextBlock>
                    <TextBlock Grid.Row="2" Grid.Column="1"> 
                    <Hyperlink Click="HelpHyperlinkClick"> 
                        <Image Source="{Binding HelpIconFilePath}"></Image>
                    </Hyperlink>
                    </TextBlock>
                </Grid>
            </Border>                
        </Grid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition Name="columnWidth" MaxWidth="350"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid x:Name="horizontalGrid">                
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" MinHeight="125"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Name="rowHeight" MinHeight="150"></RowDefinition>
                </Grid.RowDefinitions>

                <dx:DXTabControl Grid.Row="0"  
                    Margin="10 0 5 5"
                    Name="MainTabRegion"  
                    SelectedIndex="{Binding Tabs.SelectedIndex}" 
                    ItemsSource="{Binding Tabs.TabItems}"  
                    DestroyContentOnTabSwitching="False" BorderThickness="5"                          
                    OverridesDefaultStyle="True">
                    <dx:DXTabControl.View>
                        <dx:TabControlScrollView 
                                     ShowHeaderMenu="True"  
                                     AllowHideTabItems="True" 
                                     CloseHeaderMenuOnItemSelecting="True" ShowHiddenTabItemsInHeaderMenu="True" />
                    </dx:DXTabControl.View>

                    <dx:DXTabControl.ItemContainerStyle>
                        <Style TargetType="{x:Type dx:DXTabItem}">
                            <Setter Property="Visibility" Value="{Binding IsVisible, Mode=OneWay, Converter={StaticResource boolToVis}}"/>
                        </Style>
                    </dx:DXTabControl.ItemContainerStyle>
                    <dx:DXTabControl.ItemHeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Header}" 
                                        Visibility="{Binding IsVisible, Mode=OneWay, Converter={StaticResource boolToVis}}"
                                        OverridesDefaultStyle="True" />
                        </DataTemplate>
                    </dx:DXTabControl.ItemHeaderTemplate>
                </dx:DXTabControl>

                <GridSplitter  Grid.Row="1" 
                  Margin="10 0 5 5"
                  HorizontalAlignment="Stretch" 
                  VerticalAlignment="Stretch"              
                  ShowsPreview="true"
                  ResizeDirection="Rows"                      
                  Height="5" />
                <Border Grid.Row="2" Margin="10 0 5 5">
                    <ContentControl Content="{Binding Path=Basket}" />
                </Border>
            </Grid>

            <GridSplitter Margin="0 20 0 0" Grid.Column="1"
              HorizontalAlignment="Stretch" 
              VerticalAlignment="Stretch"              
              ShowsPreview="true"
              ResizeDirection="Columns"
              x:Name="verticalSplitter"                    
              DragCompleted="OnDragCompleted"
              Width="5" />                

             <Border Grid.RowSpan="3" Grid.Column="2"  Margin="3 20 0 0">
                    <ContentControl Content="{Binding Path=ColumnDataPreview}" />
             </Border>

        </Grid>

    </Grid>
    <Grid Height="25" Width="300" Visibility="{Binding ShowProgress, Converter={StaticResource boolToVis}}">
        <ProgressBar IsIndeterminate="True" Orientation="Horizontal" />
        <Viewbox>
            <TextBlock Text="Loading ..." Padding="50 0"/>
        </Viewbox>
    </Grid>
</Grid>

I know this is old -- but we stumbled on to this with a legacy Office add-in that we support -- where one user is apparently experiencing this same issue.

We did some digging, and stumbled across this similar SO post: Blank WPF child windows on Windows 10

It looks like there are two options:

  1. Instruct the user to update/fix their bad video card drivers.

  2. Put a hack into the code that will force the content to redraw at just the right instant (ie InvalidateVisual is not sufficient, see the linked question's answers for more information).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM