来自networkshare的UWP XAML ImageBrush.imageSource [英] UWP XAML ImageBrush.imageSource from networkshare

查看:61
本文介绍了来自networkshare的UWP XAML ImageBrush.imageSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编辑了我的问题:

我有一个带有面板按钮的堆栈面板. 现在我想从网络共享图像中设置按钮背景.

i have a stack panel with buttons from array. now I want to set the Button Background from networkshare images.

这是我的源代码:

XAML:

<Page
x:Class="App4.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App4"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Height="1205.722" Width="2045.722">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="0,0,0,0">
    <StackPanel x:Name="sp" HorizontalAlignment="Left" Height="1070" Margin="10,10,0,0" VerticalAlignment="Top" Width="145" Padding="0" CornerRadius="10" RequestedTheme="Light" ScrollViewer.HorizontalScrollBarVisibility="Visible" Grid.RowSpan="2">
        <FlyoutBase.AttachedFlyout>
            <MenuFlyout/>
        </FlyoutBase.AttachedFlyout>
    </StackPanel>
</Grid>

代码背后:

private void onLoad()
    {


        for (int i = 0; i < imgNames.Length; ++i)
        {
            ImageBrush brush1 = new ImageBrush();
            brush1.ImageSource = new BitmapImage(new Uri("ms-appx:///assets/" + imgNames[i]));
            Button button = new Button()
            {
                Content = string.Format(""),
            Tag = i
            };
            button.Width = 100;
            button.Height = 100;
            button.Background = brush1;
            button.Margin = new Thickness(0, 20, 0, 0);


            button.Click += new RoutedEventHandler(button_Click);   

            this.sp.Children.Add(button);


        }
    }

谢谢

推荐答案

要从网络源加载图像,您需要在应用中使用这些功能

For loading image from network source you need to use these capabilities in your app

<Capabilities>
  <Capability Name="internetClient" />
  <Capability Name="privateNetworkClientServer" />
  <Capability Name="internetClientServer" />
  <uap:Capability Name="enterpriseAuthentication" />
</Capabilities>

和您的图片

<Image Name="YourImageElementName" />

并在后面的代码中加载图片

and loading image in code behind

StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(@"\\Your Image Full Path e.g user\folder\subfolder");
StorageFile file = await folder.GetFileAsync("ImageName.jpg");
using (var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
    BitmapImage bitmap = new BitmapImage();
    bitmap.SetSource(stream);
    YourImageElementName.Source = bitmap;
}

我为此 https://github.com/shubdragon/创建的

Github示例 LoadNetworkImageRepo

Github sample i created for this https://github.com/shubdragon/LoadNetworkImageRepo

需要注意的要点

1)您需要使用代码和图像名称以及所需的扩展名来设置网络位置.

1) You need to set your network location in code and image name with required extension.

2)必须将该位置共享给家庭组.

2) must share that location to homegroup.

3)注意后面不同页面和Package.appxmanifes中的代码(在xml编辑器中以代码形式查看)

3) Note code behind in different pages and Package.appxmanifes (view it as code in xml editor)

这篇关于来自networkshare的UWP XAML ImageBrush.imageSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆