Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.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中的WPF中为不同的菜单下载和使用不同的背景#_C#_Css_Wpf - Fatal编程技术网

C# 在c中的WPF中为不同的菜单下载和使用不同的背景#

C# 在c中的WPF中为不同的菜单下载和使用不同的背景#,c#,css,wpf,C#,Css,Wpf,好的,在我的应用程序上使用WPF,我的应用程序的背景图片我想在每次不同的菜单更改时更改另一个背景 “菜单框” 目前它只在 “Trainer.ContentPage” ,发现于 ImageSource=“/Trainer;component/Resources/content.jpg” 我已经准备好通过令牌接收不同的菜单选项背景文件, 我可以通过以下方式访问: oS.fullUrl = $"http://Mysite-testing.net/t_server/download.php?token=

好的,在我的应用程序上使用WPF,我的应用程序的背景图片我想在每次不同的菜单更改时更改另一个背景

“菜单框”

目前它只在

“Trainer.ContentPage” ,发现于 ImageSource=“/Trainer;component/Resources/content.jpg”

我已经准备好通过令牌接收不同的菜单选项背景文件, 我可以通过以下方式访问:

oS.fullUrl = $"http://Mysite-testing.net/t_server/download.php?token={selectedMenu.key}";
如何在我的应用程序的WPF设置和C#代码方面下载并使用下载的背景图像

<TextBlock Text="Select Menu:" Foreground="White" VerticalAlignment="Center" Grid.Column="2" Margin="16,0,0,0"/>
            <ComboBox Name="menuComboBox" Width="Auto" Margin="8,0,0,0" VerticalAlignment="Center" Grid.Column="3"
                      IsEnabled="{Binding IsChecked, Converter={StaticResource InverseBooleanConverter}, ElementName=enableButton}" 
                      SelectionChanged="menuComboBox_SelectionChanged"/>    

正确..通过从下载的文件创建位图图像(如wpf部分),在C#中完成了更多操作

private void updateBackground(MenuSelect _menu)
    {
        // Check Background
        if (!String.IsNullOrEmpty(_menu.BackGround))
        {
            // Web Client Object
            using (var objClient = new WebClient())
            {
                try
                {
                    // Download Image
                    String szUrlAddress = String.Format("http://my_site.com/t_server/download.php?token={0}", _menu.BackGround);
                    byte[] imgData = objClient.DownloadData(szUrlAddress);
                    if (imgData.Length > 0)
                    {
                        using (var objStream = new MemoryStream(imgData))
                        {
                            // Create Bitmap Image
                            var myBitmapImg = new BitmapImage();
                            myBitmapImg.BeginInit();
                            myBitmapImg.StreamSource = objStream;
                            myBitmapImg.CacheOption = BitmapCacheOption.OnLoad;
                            myBitmapImg.EndInit();
                            myBitmapImg.Freeze();

                            // Create Image
                            Image myImage = new Image();
                            myImage.Source = myBitmapImg;

                            // Create Image Brush
                            ImageBrush myBrush = new ImageBrush();
                            myBrush.ImageSource = myImage.Source;

                            // Set Background
                            this.Background = myBrush;
                        }
                    }
                }
                catch (WebException ex)
                {
                    log("Background Exception: \"" + ex.Message);
                }
            }
        }
    }

private void selectMenu(MenuSelect _menu)
        {
...
...
...
 Manager.Instance.selectMenu(_menu);
 updateBackground(_menu);

 ...
 ...
 }


<TextBlock Text="Select Menu:" Foreground="White" VerticalAlignment="Center" Grid.Column="2" Margin="16,0,0,0"/>
            <ComboBox Name="menuComboBox" Width="Auto" Margin="8,0,0,0" VerticalAlignment="Center" Grid.Column="3"
                      IsEnabled="{Binding IsChecked, Converter={StaticResource InverseBooleanConverter}, ElementName=enableButton}" 
                      SelectionChanged="menuComboBox_SelectionChanged"/>    
private void updateBackground(菜单选择菜单)
{
//检查背景
如果(!String.IsNullOrEmpty(_menu.BackGround))
{
//Web客户端对象
使用(var objClient=new WebClient())
{
尝试
{
//下载图像
String szUrlAddress=String.Format(“http://my_site.com/t_server/download.php?token={0}”,_menu.BackGround);
字节[]imgData=objClient.DownloadData(szUrlAddress);
如果(imgData.Length>0)
{
使用(var objStream=newmemoryStream(imgData))
{
//创建位图图像
var myBitmapImg=新的BitmapImage();
myBitmapImg.BeginInit();
myBitmapImg.StreamSource=objStream;
myBitmapImg.CacheOption=BitmapCacheOption.OnLoad;
myBitmapImg.EndInit();
myBitmapImg.Freeze();
//创造形象
Image myImage=新图像();
myImage.Source=myBitmapImg;
//创建图像笔刷
ImageBrush myBrush=新的ImageBrush();
myBrush.ImageSource=myImage.Source;
//背景
this.Background=myBrush;
}
}
}
捕获(WebException ex)
{
日志(“后台异常:\”“+ex.Message”);
}
}
}
}
专用无效选择菜单(菜单选择菜单)
{
...
...
...
Manager.Instance.selectMenu(\u菜单);
updateBackground(_菜单);
...
...
}