2017-06-12 72 views
-1

好吧,我的應用程序使用WPF,我的應用程序的背景圖片我想換另一種背景與下載和使用在WPF在C#中不同的菜單不同的背景

每個不同的菜單變化「menuComboBox」

目前其僅在

「Trainer.ContentPage」 ,在 的ImageSource = 「/訓練師;組件/資源/ content.jpg」 找到

IVE作出規定以接收不同的菜單選項背景文件通令牌, 我可以訪問具有:

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"/>  

回答

0

Right..got它做,更在C#中,從下載的文件創建位圖圖像,作爲WPF部分

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"/>