[SL] Resource로 된 이미지 불러오는 방법

사용자 삽입 이미지

이미지를 불러와서 컨트롤에 삽입하는 방법은 크게 두가지가 있다.

웹상에 있는 파일을 불러와서 로드 하는 방법
XAP파일에 포함시켜서 그 파일을 로드하는 방법

웹상에 있는 이미지 같은 경우는 간단하게 적어주면 된다.

[code xml]
<Image Source="http://reikop.com/buffering_bg.png"/>
[/code]
[code c#]
Uri uri = new Uri("http://reikop.com/buffering_bg.png", UriKind.Absolute);
Image img = new Image();
img.Source = new BitmapImage(uri);
Child.Add(img);
[/code]


그리고 XAP에 포함되어있는 파일은 어셈블리와 함께 적어주면 된다.

[code xml]
<Image Source="/ZetPlayer;component/Asset/buffer_gb.png"/>
[/code]

[code c#]
Uri uri = new Uri("/ZetPlayer;component/Asset/buffer_gb.png", UriKind.Relative);
Image img = new Image();
img.Source = new BitmapImage(uri);
Child.Add(img);
[/code]

다른 어셈블리에 있어도 똑같이 적용해주면 되겠다~
사용자 삽입 이미지

주의할점은 Uri가 상대경로(Relative)인지 절대경로(Absolute)인지 확실히 해야 한다는 점이다.
그리고 이미지 앞에 component/ 라는 경로를 적어주어야 한다.

빌드작업에 Resource가 되어있어야 XAP에 포함된다.

Posted by reiKop

2009/04/01 02:22 2009/04/01 02:22
, , , , , , , ,
Response
No Trackback , No Comment
RSS :
http://reikop.raony.net/blog/rss/response/76

[SL] 값을 포함해서 이벤트를 송출하자!~

전에 소개했던 이벤트 송출 방식에는 이벤트의 발생만 나타낼수만 있다.
하지만 지금 포스팅하는 문서에는 값을 포함햇 이벤트를 발생할수 있는법을 제시한다.

[code c#]
public event RoutedPropertyChangedEventHandler<double> VolumnChanged;
protected virtual void OnVolumnChanged(double oldValue, double newValue)
{
    RoutedPropertyChangedEventHandler<double> handler = VolumnChanged;
    if (handler != null)
    {
        handler(this, new RoutedPropertyChangedEventArgs<double>(oldValue, newValue));
    }
}
[/code]

이벤트를 발생시키려면

[code c#]
OnVolumnChanged( 0.9 , 1.0 );
[/code]

Posted by reiKop

2009/03/23 10:51 2009/03/23 10:51
, , ,
Response
A trackback , No Comment
RSS :
http://reikop.raony.net/blog/rss/response/73

[SL] 브라우져의 리사이즈 이벤트

플래시에서는 브라우져가 크기가 변경될시에 발생하는 이벤트가 있다.

[code java]
addEventListener("resize",resizeEvent);
function resizeEvent(e:Event):void
{
    trace( this.width, this.height );
}
[/code]


실버라이트에서는 이것을 찾는게 어려웠다.
Resize 라는 이벤트도 없고 난감했는데 구글링을 통해 쉽게 답을 얻었다.


[code c#]
public Page(){
    InitializeComponent();
    App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
}
[/code]

이벤트를 받아온 함수에서는 값을 받아오면 된다!

[code c#]
void Content_Resized(object sender, EventArgs e){
     double height = App.Current.Host.Content.ActualHeight;
     double width = App.Current.Host.Content.ActualWidth;
}
[/code]

참고한 사이트
http://silverlight.net/blogs/msnow/archive/2008/06/06/browser-resize-how-to-determine-your-browser-size.aspx

Posted by reiKop

2009/03/19 15:40 2009/03/19 15:40
, , , , ,
Response
No Trackback , No Comment
RSS :
http://reikop.raony.net/blog/rss/response/72

'clr-namespace' URI가 프로젝트에서 참조되지 않은 어셈블리를 가리킵니다.


 실버라이트나 WPF 개발이 처음인 사람은 한번쯤 겪어 봤을만한 오류일것이다.

사용자 삽입 이미지

네임스페이스를 적고 어셈블리를 적었는데도 계속 저오류만 뜨고 있으니 말이다.

이걸 가지고 계속 고생했던것을 생각하면 억울하다 ㅠㅠ..

문제는 무엇이었을까??

빌드..


그렇다  빌드를 안했던것이다.-_-.;;;;

프로젝트를 생성하고 바로 네임스페이스 작업을 했으니 당연하지..

Flex 개발만 해서 그런거 같다.. 플렉스는 저장할때 빌드해 주니..

빌드된 DLL파일이나 XAP에서 참조해 오는건데 빌드가 된것이 없으니 이런 에러를 ..

같은 문제로 고민하지 말았으면해서 이포스트를 남긴다.

Posted by reiKop

2009/03/18 10:10 2009/03/18 10:10
, , , , ,
Response
A trackback , No Comment
RSS :
http://reikop.raony.net/blog/rss/response/71

[SL] 풀스크린 지정하기

동영상 플레이어나 특이한상황에서 풀스크린 지정이 필요할 때가 있다.
이때는 이렇게 해주면 된다.

[code c#]
void FullScreen()
{
    System.Windows.Interop.SilverlightHost host =  Application.Current.Host;
    System.Windows.Interop.Content content = host.Content;
    content.IsFullScreen = true;
}
[/code]

원래 화면으로 돌아오려면
Windows 는 Alt+F4, ESC 키
MAC 은 ESC키면 돌아온다.

그리고 전체화면으로 됐을때 사이즈를 알고 싶으면 이벤트를 등록하면 된다.

[code c#]
content.FullScreenChanged += new EventHandler(content_FullScreenChanged);
void content_FullScreenChanged(object sender, EventArgs e)
{
    content.ActualHeight;
    content.ActualWidth;
}
[/code]

참 쉽죠잉

Posted by reiKop

2009/03/12 09:49 2009/03/12 09:49
, , ,
Response
No Trackback , No Comment
RSS :
http://reikop.raony.net/blog/rss/response/70

[SL] delegate란 무엇인가?


delegate는 무엇일까?


 다른 Method에 대한 참조를 가지고 있다가 delegate를 호출하면 자신이 참조하고 있는 Mathod를 실행하는 것이다.

사전적 의미는 대표자;위임하다;대표로 위임하다 라는 뜻이네요



일단 delegate를 선언을 하게 되면 그 delegate는 함수를 참조하게 된다.

[code c#]
using System;
namespace ex_10_delegate
{
    class Program
    {
        public delegate void PrintOut(string s); // delegate declare
        public static void WriteToConsole(string s)
        {
            Console.WriteLine(s);
        }
        static void Main(string[] args)
        {
            PrintOut printout = new PrintOut(WriteToConsole);
            printout(" PrintOut을 호출한다");
            printout("PrintOut은 다시 WriteToConsole을 호출한다");
        }
    }
}
[/code]


특이한 점은 delete에 함수를 "+" 연산자를 써서 연속적으로 함수 호출이 가능하다는 것이다.

[code c#]
using System;
namespace delegate_coffee
{
    class Program
    {
        public delegate void Stuff(); // delegate declare
        public static void Sugar()
        {
            Console.WriteLine("Sugar");
        }
        public static void Cream()
        {
            Console.WriteLine("Cream");
        }
        public static void Milk()
        {
            Console.WriteLine("Milk");
        }
        public static void Coffee()
        {
            Console.WriteLine("Coffee");
        }
        static void Main(string[] args)
        {
            Stuff S = new Stuff(Sugar);
            Stuff C = new Stuff(Cream);
            Stuff M = new Stuff(Milk);
            Stuff Cafe = new Stuff(Coffee);
            Console.WriteLine("비엔나 커피 만들기: ");
            Stuff Vienna = S + C + Cafe;
            Vienna();
            Console.WriteLine("블랙 커피 만들기: ");
            Stuff  BlackCoffee = S  + Cafe;
            BlackCoffee();
        }
    }
}
/*
*델리게이트 객체는 메모리에서 할당될 때 생성자에 매개 변수로 메쏘드를 넘겨 받는다. 이 메쏘드를 Named Method라 한다.
*/
[/code]


그리고 deleate는 익명함수를 만들수 있다.
[code c#]
using System;
namespace delegate_Annonymouse
{
    class Program
    {
        public delegate void PrintOut(string s);
        static void Main(string[] args)
        {
            //익명 메쏘드 정의
            PrintOut printout = delegate(string s)
            {
                Console.WriteLine(s);
            };
            printout("익명 메쏘드");
            printout("쉬윈가 쉽지 않은가?");
        }
    }
}
/*
* 익명 메쏘드는 재사용되지 않는 코드를 가진 메쏘드를 델리게이트가 호출하게 될 경우에 유용하게 사용될 수 있다.
*/
[/code]

마지막으로 이벤트를 응용한다.

[code c#]
using System;
namespace delegate_event
{
    class Client
    {
        private int ID;
        public delegate void ClientService(object sender, EventArgs args);
        public event ClientService Service;
        public Client(int ID)
        {
            this.ID = ID;
        }
        public int ClientID
        {
            get { return this.ID; }
        }
        public void FireEvent()
        {
            if (Service != null)
            {
                EventArgs args = new EventArgs();
                Service(this, args);
            }
        }
    }
    class Program
    {
        public static void OnEvent(object sender, EventArgs args)
        {
            Client client = (Client)sender;
            Console.WriteLine("{0} , event fire", client.ClientID);
        }
        static void Main(string[] args)
        {
            Client clientA = new Client(1);
            clientA.Service += new Client.ClientService(OnEvent);
            clientA.FireEvent();
        }
    }
}
[/code]

Posted by reiKop

2009/03/11 16:02 2009/03/11 16:02
, , ,
Response
No Trackback , No Comment
RSS :
http://reikop.raony.net/blog/rss/response/69

[SL] 커스텀 이벤트

플렉스 개발자를 위한 실버라이트 개발

 플래시에서는 dispatchEvent를 사용해서 이벤트를 송출하고 addEventListener로 이벤트를 받는다.

[code]
dispatchEvent(new Event('test'),testFn);
function testFn(e:Event):void
{
    trace(e.type);
}
[/code]

 그렇다면 실버라이트에서는 어떻게 할까?
우선 이벤트 등록은

[code c#]public event EventHandler Test;[/code]
이렇게 하게되면 다른 클래스에서 Test라는 이벤트를 등록해서 사용할수 있다.
[code c#]
클래스.Test += new EventHandler(e_test);
 void e_Test(object sender, EventArgs e)
{
    MessageBox.Show("EventDispatched");
}
[/code]

 이젠 이벤트를 Fire해볼까? 간단하게 변수값과함께 이벤트를 송출한다.
그전에 null값 체크하고서 송출해주어야 한다.
[code c#]
 Test(this, null);
[/code]

SL정보는 틀릴수가 있으므로 다른내용이 있다면 댓글을 부탁드립니다.

Posted by reiKop

2009/03/11 14:39 2009/03/11 14:39
, , , ,
Response
A trackback , No Comment
RSS :
http://reikop.raony.net/blog/rss/response/68


블로그 이미지

HTML, Javascript 이야기

- reiKop

Notices

  1. 첫글.

Archives

Authors

  1. reiKop

Calendar

«   2010/03   »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Site Stats

Total hits:
26925
Today:
9
Yesterday:
36