简体   繁体   English

UWP-BitMapImage到图标

[英]UWP - BitMapImage to Icon

I'm trying to make a UWP with Visual Studio 2017. I want to add as a NavigationViewItem the Microsoft Account Information. 我正在尝试使用Visual Studio 2017制作UWP。我想将Microsoft帐户信息添加为NavigationViewItem In order to do it I get with GraphServiceClient the DisplayName and the profile picture saved as string and BitMapImage respectively. 为了做到这一点,我使用GraphServiceClient获得了DisplayName和配置文件图片,分别保存为字符串和BitMapImage

What I would like to do is to crop circularly the BitMapImage and use it in the Icon property of the NavigationViewItem . 我想做的是循环裁剪BitMapImage并将其用于NavigationViewItemIcon属性。

What I would like to do is to crop circularly the BitMapImage and use it in the Icon property of the NavigationViewItem. 我想做的是循环裁剪BitMapImage并在NavigationViewItem的Icon属性中使用它。

You could not use BitmapImage as NavigationViewItem's Icon , It only receives IconElement . 您不能将BitmapImage用作NavigationViewItem的Icon ,它只能接收IconElement

To achieve your target, you could directly do layout in NavigationViewItem.Content to show image and text. 要实现目标,您可以直接在NavigationViewItem.Content进行布局以显示图像和文本。 For example, you could use Ellipse and ImageBrush to show image in circle shape. 例如,您可以使用EllipseImageBrush以圆形显示图像。

Here's a simple code sample: 这是一个简单的代码示例:

<NavigationView>
        <NavigationView.MenuItems>
            <NavigationViewItem Name="SalahNavItem" Tag="Salah">
                <NavigationViewItem.Content>
                    <StackPanel Orientation="Horizontal" >
                        <Ellipse Width="40" Height="40">
                            <Ellipse.Fill>
                                <ImageBrush x:Name="img"></ImageBrush>
                            </Ellipse.Fill>
                        </Ellipse>
                        <TextBlock Text="Custom" VerticalAlignment="Center"></TextBlock>
                    </StackPanel>
                </NavigationViewItem.Content>
            </NavigationViewItem>
            <NavigationViewItem Name="AppsNavItem"  Content="Apps" Tag="apps">
            </NavigationViewItem>
        </NavigationView.MenuItems>
</NavigationView>
BitmapImage bitmapImage = new BitmapImage(new Uri("ms-appx:///Assets/car.png"));
img.ImageSource = bitmapImage;

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM