1

我是 WPF 的新手,我试图在 WPF 窗口中显示图像,然后显示一个按钮,以及绝对坐标中的两个链接。我有两个问题:

  1. 浮动控件从一台计算机移动到另一台计算机
  2. 图像模糊。我认为正在调整大小。

表单必须是固定对话框,图片大小为800x560。

这是我的代码:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="A.B.C.IntroGuideWindow"
        Title="Intro guide" Icon="../Resources/app_icon.ico"
        Background="{DynamicResource DialogBackgroundBrush}" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
        WindowStyle="None"
        Style="{DynamicResource WindowStyle}" SnapsToDevicePixels="True" TextOptions.TextFormattingMode="Display" Width="830" Height="660">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../ResourceDictionaries/Colors.xaml"/>
                <ResourceDictionary Source="../ResourceDictionaries/BasicStyles/StandardWindowStyle.xaml"/>
                <ResourceDictionary Source="../ResourceDictionaries/ButtonStyles/ActionFlatButtonStyle.xaml"/>
                <ResourceDictionary Source="../ResourceDictionaries/ButtonStyles/CancelButtonStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid VerticalAlignment="Top">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" MinHeight="22"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TextBlock Margin="10,10,10,10" FontFamily="Segoe UI" FontSize="21"
            FontWeight="SemiBold" Foreground="{DynamicResource FontBrush}" Grid.Row="0">
            <Run Text="Intro guide" />
        </TextBlock>
        <Button x:Name="closeButton" Style="{DynamicResource CloseChromeButtonStyle}"
            Click="CancelButton_Click" Grid.Row="0"
            Content="r" HorizontalAlignment="Right" Margin="0,6,6,0" FontFamily="Webdings" IsTabStop="False" />
        <Image x:Name="CurrentImage" Grid.Row="1" Width="800" Height="560" Stretch="None" Source="Images/sm-eval-guide-09.png" SnapsToDevicePixels="True"/>
        <Button x:Name="OpenSamplesButton" Content="Click here to open the samples directory" IsDefault="False"
            Style="{DynamicResource ActionFlatButtonStyle}"
            Margin="256,115,265,434" Width="301" Height="23" Click="OpenSamplesButton_Click" Grid.Row="1"/>
        <TextBlock x:Name="DocumentationLink" Margin="2,221,-2,333" Grid.Row="1" TextAlignment="Center" VerticalAlignment="Center" FontFamily="Arial" FontSize="14" FontWeight="Bold">
            <Hyperlink Foreground="#00A586" NavigateUri="http://www.example.com/#documentation">http://www.example.com/#documentation</Hyperlink>
        </TextBlock>
        <TextBlock x:Name="TwitterLink" Margin="590,415,84,137" Grid.Row="1" VerticalAlignment="Center" FontFamily="Arial" FontSize="16" FontWeight="Bold">
            <Hyperlink Foreground="#00A586" NavigateUri="https://twitter.com/xxx">@xxx</Hyperlink>
        </TextBlock>
        <Grid VerticalAlignment="Top" Grid.Row="2">
            <Button x:Name="PreviousButton" Content="Previous" IsDefault="False"
                Style="{DynamicResource ActionFlatButtonStyle}"
                Margin="0,0,200,10" Width="90" HorizontalAlignment="Right" Click="PreviousButton_Click"/>
            <Button x:Name="NextButton" Content="Next" IsDefault="True"
                Style="{DynamicResource ActionFlatButtonStyle}"
                Margin="0,0,105,10" Width="90" HorizontalAlignment="Right" Click="NextButton_Click"/>
            <Button x:Name="CloseButton" Content="Close" IsDefault="False"
                Style="{DynamicResource ActionFlatButtonStyle}"
                Margin="0,0,10,10" Width="90"
                VerticalAlignment="Bottom" HorizontalAlignment="Right" Click="CloseButton_Click"/>
            <CheckBox x:Name="DontShowAgainCheckbox" Content="Don't show this window again." HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Checked="DontShowAgainCheckbox_Checked"/>
        </Grid>
    </Grid>
</Window>
4

1 回答 1

4
  1. WPF 会根据正在运行的显示器的像素密度进行调整。考虑使用网格列或其他布局控件,例如StackPanel代替边距偏移。例如,您的按钮可以使用以下布局:

    <StackPanel Orientation="Horizontal" Margin="10,0" HorizontalAlignment="Right">
        <Button x:Name="PreviousButton" Content="Previous" IsDefault="False"
            Style="{DynamicResource ActionFlatButtonStyle}" Margin="4,0"
            Width="90" Click="PreviousButton_Click"/>
        <Button x:Name="NextButton" Content="Next" IsDefault="True"
            Style="{DynamicResource ActionFlatButtonStyle}" Margin="4,0"
            Width="90" Click="NextButton_Click"/>
        <Button x:Name="CloseButton" Content="Close" IsDefault="False"
            Style="{DynamicResource ActionFlatButtonStyle}" Margin="4,0"
            Width="90" Click="CloseButton_Click"/>
    </StackPanel>
    
  2. 对于模糊的图像,请尝试UseLayoutRounding="False"在您的Image定义中使用。

于 2013-10-10T16:30:24.450 回答