Combobox在Windows XP中为空,但在Windows 7中为空

时间:2012-06-08 19:49:46

标签: wpf combobox windows-xp

我已经编写了这个WPF,我有一些绑定到ObservableCollection对象的组合框。当我在Windows 7中运行应用程序时,绑定工作完美,一切都很好。当我在WindowsXP中运行它时,一切看起来都不错,但是下拉列表是空的。任何人都有这方面的经验,并以某种方式修复它?

这是XAML(部分):

<StackPanel x:Name="spUnrecRxItems">
    <Border BorderBrush="Silver" CornerRadius="3,3,3,3" BorderThickness="0,3,0,0" Height="Auto" 
                    HorizontalAlignment="Left" Margin="23,6,0,0" Width="200" Background="#FFEFEEEE">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Name="tbUR1" Foreground="#FFDE2226" FontSize="14" FontWeight="Bold" 
        TextWrapping="Wrap" Width="Auto" HorizontalAlignment="Left" FontFamily="Arial" Grid.Row="0" 
        Margin="10,10,0,0" Text="{Binding DrugName}" />
            <TextBlock Foreground="#FF484747" HorizontalAlignment="Left" 
           Margin="10,0,0,0"  FontSize="12" Text="{Binding FillMinMaxDate}" Grid.Row="1" />
            <TextBlock Foreground="#FF484747" HorizontalAlignment="Left" 
           Margin="10,0,0,0"  FontSize="12" Text="{Binding PhysiciansName}" Grid.Row="2" />
            <TextBlock ForceCursor="False" Foreground="#FF707170" HorizontalAlignment="Left" 
       Margin="10,0,0,0" Name="tbSourceCount" VerticalAlignment="Top" FontSize="12" 
               MouseDown="tbSource_MouseDown" Text="{Binding SourceCount, StringFormat=Source ({0})}" Grid.Row="3">
            </TextBlock>
        </Grid>
    </Border>
    <Expander x:Name="expManualRec" Background="DarkGray" Width="180" HorizontalAlignment="Center">
        <Expander.Header>
            <TextBlock HorizontalAlignment="Center" Text="Reconcile" Foreground="White" />
        </Expander.Header>
        <Grid Height="Auto">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <ComboBox x:Name="cboReconType" HorizontalAlignment="Center" Margin="8 0 0 0" Width="160" Height="Auto" Grid.Row="1" 
              SelectionChanged="cboReconType_SelectionChanged" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl}, Path=DataContext.ReconTypes}" />
            <ComboBox x:Name="cboRecReason" HorizontalAlignment="Center" Margin="8 0 0 0" Width="160" Height="Auto" Grid.Row="2"
                  SelectedValue="{Binding code}">
                <ComboBox.Style>
                    <Style TargetType="ComboBox">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=cboReconType, Path=Text}" Value="Create A Question">
                                <Setter Property="ComboBox.Visibility" Value="Hidden" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding ElementName=cboReconType, Path=Text}" Value="No Action">
                                <Setter Property="ComboBox.Visibility" Value="Visible" />
                                <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl}, Path=DataContext.ReconReasons}" />
                                <Setter Property="DisplayMemberPath" Value="description" />
                                <Setter Property="SelectedValuePath" Value="code" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding ElementName=cboReconType, Path=Text}" Value="Previous Questionnaire">
                                <Setter Property="ComboBox.Visibility" Value="Visible" />
                                <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl}, Path=DataContext.InterviewQuestionnaires}" />
                                <Setter Property="DisplayMemberPath" Value="QuestionnaireName" />
                                <Setter Property="SelectedValuePath" Value="interviewquestionnaire_id" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding ElementName=cboReconType, Path=Text}" Value="">
                                <Setter Property="ComboBox.Visibility" Value="Visible" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ComboBox.Style>
            </ComboBox>

2 个答案:

答案 0 :(得分:0)

由于某些样式,可能会发生这种情况,看起来组合框的文本前景颜色变为白色并且看起来是空的。

您应该使用Snoop进行确认,并确定应用程序中的任何样式是否将组合框项目的前景颜色设置为某种系统颜色或白色。

答案 1 :(得分:0)

我在这里很新,只有8个月的WPF新工作经验。

我在Windows 8中使用相同的方案编码,但Windows 7和XP不会在我的程序中加载ComboBox列表。

最后我发现:我使用EF6从SQL Server数据库中获取数据,但是在那个Combobox列表中,我使用了SQL(我在EF中的表中遇到了一些麻烦,无法从数据库中更新,只是想要为了让事情变得有效,所以我在SQLConnection和SQLCommand中使用了SQL。)既然我已经让EF做了这件事,那么Win7和WinXP计算机也在做我计划的事情。