Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 网格和图像重叠边界?_C#_Asp.net_Html_Wpf_Xaml - Fatal编程技术网

C# 网格和图像重叠边界?

C# 网格和图像重叠边界?,c#,asp.net,html,wpf,xaml,C#,Asp.net,Html,Wpf,Xaml,嗨,我试图绕过一个图像的角落,或者在图像顶部重叠我的边界,但是我尝试的任何东西似乎都不起作用 <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowStyl

嗨,我试图绕过一个图像的角落,或者在图像顶部重叠我的边界,但是我尝试的任何东西似乎都不起作用

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStyle="None"
        ResizeMode="NoResize"
        AllowsTransparency="True"
        WindowStartupLocation="CenterScreen"
        BorderThickness="0,0,0,0"
        Background="Transparent"
        Title="MainWindow" Loaded="Window_Loaded" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="581" d:DesignWidth="733" SizeToContent="WidthAndHeight">
    <Border BorderThickness="6" BorderBrush="Black" CornerRadius="12" Padding="0.5"
        HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid>

            <Image Height="543" HorizontalAlignment="Left" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="711" Source="/WpfApplication1;component/Images/Login.jpg" ImageFailed="image1_ImageFailed" />

            <TextBox Height="38" HorizontalAlignment="Left" Margin="205,177,0,0" Name="textBox1" VerticalAlignment="Top" Width="299" Background="#00000000" BorderBrush="#00000000" BorderThickness="0" Text="Please enter your email address." FontSize="18" Foreground="White" TextChanged="textBox1_TextChanged" />
            <TextBox Background="#00000000" BorderBrush="#00000000" BorderThickness="0" FontSize="18" Foreground="White" Height="38" HorizontalAlignment="Left" Margin="205,256,0,0" Name="textBox2" Text="Please enter your password" VerticalAlignment="Top" Width="299" />
        </Grid>


    </Border>
</Window>

是否可以在网格上重叠边界

您可以从这个屏幕转储中看到我的意思:


不行,因为您的图像是jpg,背景是固定颜色,如果无法获取或使用PS删除角点并另存为PNG,请尝试GIMP。背景将是透明的。

不行,因为您的图像是jpg,背景是固定颜色,如果无法获取或使用PS删除角并另存为PNG,请尝试GIMP。然后背景将是透明的。

为清晰起见更新了XAML,并添加了更多注释:

网格
正以圆角正确边框。这里真正的问题是:

是否可以在网格中包含的元素上重叠网格边框?

哎呀,这不可能。如果要将
网格中包含的所有内容剪裁到
边框的圆角半径,则需要将
剪裁
应用到
网格
,以便任何包含的元素都不会与边框重叠

    <Image 
        HorizontalAlignment="Center" 
        Margin="10" 
        Name="image2" 
        Stretch="None" 
        VerticalAlignment="Bottom" 
        Source="/test;component/login_btn.jpg"> <!-- Make sure it's not
                                                     a self closing tag
                                                     ending in "/>" -->
        <Image.Clip>  <!-- Image.Clip needs to be enclosed between
                           the Image opening tag (above) and
                           the Image closing tag (2 lines below). -->
            <RectangleGeometry RadiusX="18" RadiusY="18" Rect="0,0,103,30" />
        </Image.Clip>
    </Image>  <!-- Close the Image tag here. -->

图像的剪裁区域定义为带圆角的
矩形几何体。您可以调整属性以匹配按钮图像

下面是我测试的屏幕截图,其中一幅图像保持原样,另一幅图像被剪裁到几何体上:


希望这能有所帮助。

为清晰起见更新了XAML,并提供了更多评论:

网格
正以圆角正确边框。这里真正的问题是:

是否可以在网格中包含的元素上重叠网格边框?

哎呀,这不可能。如果要将
网格中包含的所有内容剪裁到
边框的圆角半径,则需要将
剪裁
应用到
网格
,以便任何包含的元素都不会与边框重叠

    <Image 
        HorizontalAlignment="Center" 
        Margin="10" 
        Name="image2" 
        Stretch="None" 
        VerticalAlignment="Bottom" 
        Source="/test;component/login_btn.jpg"> <!-- Make sure it's not
                                                     a self closing tag
                                                     ending in "/>" -->
        <Image.Clip>  <!-- Image.Clip needs to be enclosed between
                           the Image opening tag (above) and
                           the Image closing tag (2 lines below). -->
            <RectangleGeometry RadiusX="18" RadiusY="18" Rect="0,0,103,30" />
        </Image.Clip>
    </Image>  <!-- Close the Image tag here. -->

图像的剪裁区域定义为带圆角的
矩形几何体。您可以调整属性以匹配按钮图像

下面是我测试的屏幕截图,其中一幅图像保持原样,另一幅图像被剪裁到几何体上:


希望这有帮助。

我发现错误,在“image”类型中找不到可附加属性“Clip”@Garrith检查我的编辑。请确保您已将剪辑标签放置在正确的位置。@down投票人:很高兴知道为什么我的答案被否决。哪怕是一个简短的评论都会有帮助。Torrentry这很精彩,因为某种原因起作用了。我不知道为什么我的剪辑标签不起作用,但我猜这是结尾了,就像你在回答中提到的那样。起初我认为它不起作用,但高度和宽度并不直接表示图像工具提示显示的尺寸比。但我最终还是让它工作了。我得到了一个错误,在类型“image”@Garrith中找不到可附加属性“Clip”,请检查我的编辑。请确保您已将剪辑标签放置在正确的位置。@down投票人:很高兴知道为什么我的答案被否决。哪怕是一个简短的评论都会有帮助。Torrentry这很精彩,因为某种原因起作用了。我不知道为什么我的剪辑标签不起作用,但我猜这是结尾了,就像你在回答中提到的那样。起初我认为它不起作用,但高度和宽度并不直接表示图像工具提示显示的尺寸比。但我终于让一切都运转起来了。