开发者

Declaring button control in windows phone 7

I am trying t开发者_如何学Co declare a button named "viewButton" with a image as the background of the button. How can i go about doing it can anyone help me with it? Below is the code i tired but is not a correct one.

Code: viewButton.Background = "/AlarmClock;component/Images/page_preview.png";


<Button>
    <Button.Background>
        <ImageBrush Source="/AlarmClock;component/Images/page_preview.png" />
    </Button.Background>
</Button>

just make sure the file is maked as "Resource" in visual studio. Alternatively you can mark it as "Content" and use it like this:

        <ImageBrush Source="/Images/page_preview.png" />

I don't know if you need to assign the background programatically (because you can do it in markup), but if you do here is what you need to say:

viewButton.Background = new ImageBrush
{
    Source = new BitmapImage(new Uri("", UriKind.Relative))
}

[FURTHER]

in order set margin programmatically:

viewButton.Margin = new Thickness(left, top, right, bottom);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜