为什么单选按钮不会出现在Windows 8的弹出窗口中?

时间:2014-04-16 14:20:26

标签: c# wpf xaml radio-button

我使用VS2010在Windows 7上开发了WPF / C#/ .NET 4.0应用程序。该应用程序运行良好,在XP和Windows 7上运行良好。但是,在具有最新更新的Windows 8上,除了默认选择的按钮之外,单选按钮不会出现在弹出窗口上,因为它存在空间。如果将鼠标移动到单选按钮所在的位置,则按钮会在鼠标悬停时显示。当鼠标从它上面移开时,按钮就会出现,因为当鼠标不在它上面时,它应该以它开始时的方式显示,但是没有。

在我有单选按钮的所有其他情况下,它们可以正常工作,除非它们没有按照应有的方式对齐。它们在XP和Windows 7中正确对齐。

更正:我使用.NET 3.5开发它,最近更改为.NET 4.0平台。在.NET 3.5平台上编译并在Windows 8上运行时,这些单选按钮会按原样显示。除了切换到.NET 4.0平台和编译之外没有改变任何东西,然后在Windows 8下运行,单选按钮不再显示它们应该出现,但是当鼠标移过它们时它们应该显示出来。

首次显示弹出窗口时,如何让这些单选按钮出现在非鼠标悬停状态?

这是弹出式XAML,所有其他控件在Windows 8中显示并正常工作,例如CheckBoxes:

<Popup Name="MainPrintMenu"
        PlacementTarget="{Binding ElementName=btnPrint}"
        Placement="Bottom"
        HorizontalOffset="-99"
        VerticalOffset="-5"
        AllowsTransparency="True"
        StaysOpen="False">
    <Border BorderThickness="2"
            Background="White"
            CornerRadius="5"
            BorderBrush="Black">
        <Grid Background="Transparent">
            <StackPanel Name="PrintButtons"
                        Orientation="Vertical"
                        Background="Transparent"
                        Margin="5"
                        >
                <StackPanel.Resources>
                    <Style TargetType="Button">
                        <Setter Property="FontSize" Value="12" />
                        <Setter Property="FontWeight" Value="Bold" />
                        <Setter Property="HorizontalContentAlignment" Value="Center" />
                        <Setter Property="BorderBrush" Value="{x:Null}" />
                    </Style>
                    <Style TargetType="RadioButton">
                        <Setter Property="FontSize" Value="10" />
                        <Setter Property="FontWeight" Value="Bold" />
                        <Setter Property="HorizontalContentAlignment" Value="Left" />
                        <Setter Property="BorderBrush" Value="{x:Null}" />
                        <Style.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.50" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                    <Style TargetType="CheckBox">
                        <Setter Property="FontSize" Value="10" />
                        <Setter Property="HorizontalContentAlignment" Value="Left" />
                        <Setter Property="Margin" Value="18,0,0,10" />
                        <Setter Property="BorderBrush" Value="{x:Null}" />
                        <Style.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.50" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </StackPanel.Resources>

                <RadioButton Name="MainPrintMenu_PQAI" GroupName="PM" Content="Print My 911 Info" IsChecked="True" />
                <StackPanel Orientation="Vertical" IsEnabled="{Binding ElementName=MainPrintMenu_PQAI, Path=IsChecked}" Margin="18,0,0,0">
                    <RadioButton Name="MainPrintMenu_PQAIR" GroupName="PM_PQAI" Content="Report" IsChecked="True" />
                    <CheckBox Name="PQAI_Blank" Content="Print blank entries too" IsEnabled="{Binding ElementName=MainPrintMenu_PQAIR, Path=IsChecked}" Margin="18,0,0,0" />
                    <RadioButton Name="MainPrintMenu_PQAIW" GroupName="PM_PQAI" Content="Wallet Card" Margin="0,0,0,10" />
                </StackPanel>

                <StackPanel Name="PrintIfLoggedIn" Orientation="Vertical">
                    <RadioButton Name="MainPrintMenu_PAF" GroupName="PM" Content="Print All Folders"/>
                    <CheckBox Name="PAF_Blank" Content="Print blank entries too" IsEnabled="{Binding ElementName=MainPrintMenu_PAF, Path=IsChecked}" />
                    <RadioButton Name="MainPrintMenu_PCF" GroupName="PM" Content="Print Current Folder: Folder" />
                    <CheckBox Name="PCF_Blank" Content="Print blank entries too" IsEnabled="{Binding ElementName=MainPrintMenu_PCF, Path=IsChecked}" />
                    <RadioButton Name="MainPrintMenu_PCSF" GroupName="PM" Content="Print Current Sub-Folder: :[Sub-FolderName]:" />
                    <CheckBox Name="PCSF_Blank" Content="Print blank entries too" IsEnabled="{Binding ElementName=MainPrintMenu_PCSF, Path=IsChecked}" />
                    <RadioButton Name="MainPrintMenu_PCForm" GroupName="PM" Content="Print Current Form: :[From]:" />
                    <CheckBox Name="PCForm_Blank" Content="Print blank entries too" IsEnabled="{Binding ElementName=MainPrintMenu_PCForm, Path=IsChecked}" />
                    <RadioButton Name="MainPrintMenu_PQRC" GroupName="PM" Content="Print QR Code" />
                    <StackPanel Margin="18,0,0,0"  Orientation="Horizontal" >
                        <Image Source="/LR;Component/Image/LR_QR.jpg" Width="30" Height="30" Margin="0,2,5,0" VerticalAlignment="Top" />
                        <TextBlock Width="250" Height="86" FontSize="8" TextWrapping="Wrap" IsEnabled="{Binding ElementName=MainPrintMenu_PQRC, Path=IsChecked}" >
                            A QR code is a small graphic image that can be quickly scanned by smartphone and
                            other devices.<LineBreak/><LineBreak/>
                            The QR code will contain only the emergency information you entered into the Quick
                            Assist folder.<LineBreak/><LineBreak/>
                            Print the QR code and affix it to the back of your LR USB card (or elsewhere).
                            In an emergency it can be scanned and your important information available immediately
                            (no need to start LR)
                        </TextBlock>
                    </StackPanel>
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
                    <Button Content="Print" Width="233" Click="Event_MainPrintMenu_Print_Click" IsEnabled="{Binding BindingGroupName=MPM, Path=Selected}"/>
                    <Button Content="Cancel" Width="70" Click="Event_MainPrintMenu_Cancel_Click" />
                </StackPanel>

            </StackPanel>
        </Grid>
    </Border>
</Popup>

1 个答案:

答案 0 :(得分:0)

事实证明这是一个简单的解决方案。以下是上述问题的XAML部分已更改:

<Style TargetType="RadioButton">
    <Setter Property="FontSize" Value="10" />
    <Setter Property="FontWeight" Value="Bold" />
    <Setter Property="HorizontalContentAlignment" Value="Left" />
    <Setter Property="BorderBrush" Value="{x:Null}" />
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Opacity" Value="0.50" />
        </Trigger>
    </Style.Triggers>
</Style>

所需要的只是从上面的XAML中删除以下行:

<Setter Property="BorderBrush" Value="{x:Null}" />

用于设置RadioButton样式的XAML来自这里的另一篇文章,但是将值更改为我需要的值。我保留了BorderBrush值。