[英]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
并将其用于NavigationViewItem
的Icon
属性。
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. 例如,您可以使用
Ellipse
和ImageBrush
以圆形显示图像。
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.