2012-03-04 10 views
0

ボタンの背景を設定するのは、アンドロイドのdev.itより複雑です。 .xamlファイルにWP7コードでボタン画像をURLで変更する

:私はButton.Ifでこの画像を得ることができる方法

   JsonObject jsonObject = (JsonObject)JsonObject.Load(e.Result); 
       ads_address = jsonObject["imageurl"];//get a url from jsonobject 
       ImageBrush imageBrush = new ImageBrush(); 
       imageBrush.ImageSource = new BitmapImage(new Uri(ads_address));//ads url likes //"http://27.98.194.93/forum/images/2009/home_004.jpg"; 

       this.img_btn.Background = imageBrush;//this code is not work,perhaps, I can't get what I want(Image) with code "this.img_btn.Background" 

は、ボタンの背景を設定する方法は何ができません。この中

 <Button Click="Button_Click" x:Name="img_btn"> 
      <Button.Template> 
       <ControlTemplate> 
      <!--set button background that we can hanle click event--> 
        <Image HorizontalAlignment="Left" Margin="0,-69,0,479" x:Name="image1" Stretch="Fill" Width="480" Source="/myNameSpace;component/home_003.jpg" /> 
       </ControlTemplate> 
      </Button.Template> 
     </Button> 

は、ファイルを.CSコード内にURLがある。

答えて

1

この

は、使用しているイメージコントロールにその源を与え、最初とのイメージソースを作成してみてください。

文字列imagepath = "url";

イメージソースimgsrc1 =新しいBitmapImage(新しいUri(イメージパス、UriKind.RelativeOrAbsolute)); //イメージはImage/ImageBrushになります image.Source = imgsrc1;

+0

ありがとう、このように私はImageSourceをURLで設定することができます。しかし、私にとって重要なことです。言い換えれば、どのようにImageコントロールをボタンで取得できますか? –

+0

最後に私は[それ](http://stackoverflow.com/questions/9444091/how-to-reference-image-in-controltemplate "ありがとう男")、それはうまく動作します。 –

関連する問題