代码之家  ›  专栏  ›  技术社区  ›  TheGeekYouNeed

WPF在不同的计算机上显示不同

  •  1
  • TheGeekYouNeed  · 技术社区  · 15 年前

    在我的WPF应用程序中,我改变了按钮的样式,使它们在滚动、单击等时看起来不突出显示。

    在我的电脑上,这是正在发生的行为。在另一个windowsxp系统上,我看到一些按钮的大纲,我滚动或点击它们。

    编辑

    这是按钮本身

            <Button Click="Next_Click" Width="100" VerticalAlignment="Center" BorderThickness="0" BorderBrush="Black" Background="Black" IsTabStop="False" DockPanel.Dock="Right" HorizontalAlignment="Left" Height="154" Name="NextOffers">
                <Image Source="Images/offer_right_arrow.jpg" Width="100" Height="154" MaxWidth="100" MaxHeight="154" HorizontalAlignment="Left" VerticalAlignment="Top" MinWidth="100" MinHeight="154" ></Image>
            </Button>
    

    还有这个款式。

    <Style TargetType="{x:Type ListBoxItem}" x:Key="ListBoxItemStyle">
        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListBox_MouseLeftButtonDown"></EventSetter>
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border Name="Border" Padding="0,0,2,0" SnapsToDevicePixels="true">
                        <ContentPresenter />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter TargetName="Border" Property="Background" Value="Black"></Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    显然,我没有为这个按钮制作模板。

    我正在代码隐藏中动态加载我的ResourceDictionaries。

    2 回复  |  直到 15 年前
        1
  •  2
  •   FMM    15 年前

    听起来你需要为你的按钮定制一个控件模板。大多数WPF控件的默认控件模板取决于所选的Windows主题,因此无论您使用的是Windows经典主题、Aero、Royale还是其他什么,都会有一个按钮跟随该主题。如果你想让它看起来 完全一样 无论用户选择了什么操作系统或主题,使用自定义控件模板都可以省去很多麻烦。

        2
  •  1
  •   Jay    15 年前

    你看到的问题很可能是由于违约造成的 Button Chrome . 你可以用各种各样的造型 原封不动地,Windows主题将成为它丑陋的后脑勺。

    你需要重新创建 ControlTemplate 它自己。