椭圆拉伸没有效果

Ellipse stretch has no effect

任何人都可以解释为什么 StretchEllipse 元素中没有效果。无论我使用 NoneFillUniformToFill 还是 Uniform 结果总是一样的。

如果我在 DataTemplate (GridView) 中使用相同的代码,它就会正常工作。

<Button x:Name="UI_Application_LogIn_ProfilePictureButton_Button" Style="{StaticResource LogInButton}" BorderBrush="{ThemeResource SystemControlForegroundBaseMediumBrush}" IsTabStop="False" UseSystemFocusVisuals="False">
    <Grid x:Name="UI_Application_LogIn_ProfilePicture_Grid" IsHitTestVisible="False">
        <Ellipse x:Name="UI_Application_LogIn_ProfilePicture" Width="160" Height="160">
            <Ellipse.Fill>
                <ImageBrush x:Name="UI_Application_LogIn_ProfilePictureImageBrush" Stretch="UniformToFill" AlignmentY="Top"/>
            </Ellipse.Fill>
        </Ellipse>
        <Ellipse x:Name="UI_Application_LogIn_ProfilePictureNonStaticLightEffect" Width="160" Height="160" Fill="{ThemeResource SystemControlHighlightTransparentRevealBorderBrush}"/>
    </Grid>
</Button>

如果要创建圆形图像,请使用 windows 社区工具包中的 Imagex 控件

你可以看看玩玩imagex here 或者您可以通过 nuget 在 Microsoft.Toolkit.Uwp.UI.Controls 参考您的应用 至于你当前的问题,这是因为拉伸只影响 eclipse 内部的画笔而不影响 eclipse 本身,为了像这样进行比例调整,你必须将 eclipse 包裹在 Viewbox 控件,然后设置它的 Stretch 属性 就像在图像上一样

我找到了拉伸不起作用的原因。真是脑放屁。当我创建新的 ImageBrush 时,我忘记在我的代码中使用 Stretch。所以在创建新的 ImageBrush 后添加行 if (BrushStretch != null) (TargetShape.Fill as ImageBrush).Stretch = BrushStretch.Value; 解决了这个问题。

    //STORAGE FILE TO SHAPE
    public static async Task<Shape> StorageFileToShape(Shape TargetShape, StorageFile SourceStorageFile, Stretch? BrushStretch, AlignmentX? BrushAlignmentX, AlignmentY? BrushAlignmentY)
    {
        //IF SHAPE NULL RETURN NULL
        if (TargetShape == null) return null;
        //IF STORAGEFILE NULL OR NOT AVAILABLE RETURN NULL
        if (SourceStorageFile == null || !SourceStorageFile.IsAvailable) return null;
        //IF BRUSH IS NULL OR ITS TYPE ISN'T 'ImageBrush' CREATE NEW BRUSH
        if (TargetShape.Fill == null || TargetShape.Fill.GetType() != typeof(ImageBrush)) TargetShape.Fill = new ImageBrush();
        //SET STRETCH
        if (BrushStretch != null) (TargetShape.Fill as ImageBrush).Stretch = BrushStretch.Value;
        //SET ALIGNMENT X
        if (BrushAlignmentX != null) (TargetShape.Fill as ImageBrush).AlignmentX = BrushAlignmentX.Value;
        //SET ALIGNMENT Y
        if (BrushAlignmentY != null) (TargetShape.Fill as ImageBrush).AlignmentY = BrushAlignmentY.Value;
        //GET PICTURE 
        (TargetShape.Fill as ImageBrush).ImageSource = await StorageFileToBitmapImage(SourceStorageFile);
        //SET SHAPE FILL
        TargetShape.Fill = TargetShape.Fill as ImageBrush;
        //RETURN SHAPE
        return TargetShape;
    }
    //STORAGE FILE TO BITMAP IMAGE
    public static async Task<BitmapImage> StorageFileToBitmapImage(StorageFile SourceStorageFile)
    {
        BitmapImage TargetBitmapImage = new BitmapImage();
        TargetBitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
        using (var BitmapImageFileStream = await SourceStorageFile.OpenAsync(FileAccessMode.Read))
        {
            await TargetBitmapImage.SetSourceAsync(BitmapImageFileStream);
        }
        return TargetBitmapImage;
    }