GSI

음.. 디자인이란.. 어렵다..
Window Media Player 에 있는 디자인과 비슷한 느낌을 주기 위해서
포토샵으로 몇개 만들어서 적용해 봤다.

UX가 중요시 되고 있는 시점에서 디자인이란 더욱더 사용자로 하여금
요구되어 지고 있는거 같다.

웹 프로그램을 잘 짜지 못하니.. 요즘 Asp.NET 를 배우고 있는데
내년 쯤이면 나만의 웹 페이지를 만들수 있을거 같은데..

나 자신을 위해서 화이팅!!!..
Posted by gsi
:

[C++] Cast에 대해서... (펌)

C++ 2007. 9. 20. 17:14 |

관련 주소 : http://blog.naver.com/process3?Redirect=Log&logNo=20017834722
본 글은 cast 쪽을 보면서 자료로 참고 하기 위해서 퍼 왔습니다.

캐스트 연산은 주어진 식이 가지고 있는 형을 다른 형으로 강제로 바꾸는것입니다.

C++에는 (C 시절부터 존재하는 C 스타일 캐스트를 제외하고) 다음 네 가지 종류의 캐스트 연산이 있습니다.

* dynamic_cast
* static_cast
* reinterpret_cast
* const_cast

---------------
1. dynamic_cast
---------------

dynamic_cast(e)는 부모 클래스와 자식 클래스의 관계에 있는 포인터 형 사이의 변환 또는 레퍼런스 형 사이의 변환을 수행하는데,

- 같은 형 사이의 변환
- 널 포인터의 변환
- 자식 클래스로부터 부모 클래스로의 변환
과 같은 '뻔한' 경우가 아니라면 e는 다형적 형(polymorphic type; 가상 함수가 포함된 클래스 형)의 좌변값이나 포인터여야 하며, 컴파일시에 변환이 이루어지는 다른 종류의 캐스트 연산과는 달리 실행시에 동적 형(dynamic type)에 근거한 변환이 시도되고, 변환의 성공 여부를 검사하는 의미도 함께 가지고 있습니다.

포인터의 경우 변환이 실패하면 결과값은 널 포인터가 되는데, 이를 if 등의 조건 검사에 활용할 수 있습니다.

struct animal { virtual void ~animal(); };
struct dog : animal { void bark(); };
struct cat : animal { void mew(); };

void test(animal* a)
{
if (dog* d = dynamic_cast(a)) d->bark(); else
if (cat* c = dynamic_cast(a)) c->mew();
}

레퍼런스의 경우 변환이 실패하면 헤더에 정의되어 있는 std::bad_cast 예외가 발생합니다. 즉 이는 주어진 변환이 성공할 것을 알고 있을 때 주로 사용합니다.

void test(animal& a)
{
dog& d = dynamic_cast(a);
d.bark();
}

dog d; test(d); // 성공
cat c; test(c); // 실패 - std::bad_cast 예외 발생

dynamic_cast와 비슷한 성질을 가지고 있으면서 변환 대신 형 검사만 하는 typeid 연산자도 있는데, 피연산자는 식이나 형이 되고, 연산의 결과값은 헤더에 정의되어 있는 std::type_info 형의 좌변값입니다.

void test_equal(animal& x, animal& y)
{
if (typeid(x) == typeid(y)) { /* 같은 종류 */ }
else { /* 다른 종류 */ }
}

void test_dog(animal& x)
{
if (typeid(x) == typeid(dog)) { /* x is a dog */ }
}

dynamic_cast와 typeid는 C++에서 제공하는 실행시의 형 정보(RTTI; run-time type information)의 일환인데, 이를 남발하면 클래스 체계를 확장하고 관리하기가 어려워지므로 꼭 필요한 경우에만 사용하고 되도록 가상 함수를 통한 다형성을 이용하는 것이 바람직합니다.

--------------
2. static_cast
--------------

static_cast(e)는 가장 일반적인 형태의 캐스트 연산으로, 어떤 임시 변수 t를 T t(e);와 같이 선언하고 초기화하여 그 임시 변수 t의 값을 사용하는 것과 같은 암시적인 변환을 비롯하여, 산술형(char, int, double 등) 및 열거형(enum) 사이의 변환, 부모 클래스와 자식 클래스의 관계가 관련된 변환, void 형으로의 변환 등을 수행할 수 있습니다. 다만 부모 클래스와 자식 클래스 사이의 변환은 주어진 식의 동적 자료형(dynamic type)이 아닌 정적 자료형(static type)에 전적으로 의존합니다.

inline int integer_quotient(double a, double b)
{ return static_cast(a / b); }

animal* a = new dog;
dog* d = static_cast(a); // 올바른 캐스트 연산

animal* a = new cat;
dog* d = static_cast(a); // 잘못된 캐스트 연산

animal* a = new animal;
dog* d = static_cast(a); // 잘못된 캐스트 연산

-------------------
3. reinterpret_cast
-------------------

reinterpret_cast(e)는 서로 다른 형의 포인터 사이의 변환이나, 정수와 포인터 사이의 변환 등 서로 관계가 없는 형 사이의 변환을, 구현체가 정의하는 방법에 따라 수행합니다. 정수와 포인터 사이의 변환의 결과값은 주로 e를 표현하는 비트열을 그대로 정수 및 포인터로 해석한 값이 됩니다.

reinterpret_cast는 그 변환 방법이 대부분 구현체가 정의하도록 맡겨져 있어서 이식성을 떨어뜨리며, 요구된 변환이 올바른 변환인지의 여부를 검사하지 않으므로 신중하게 사용해야 합니다.

unsigned char* const video_base =
reinterpret_cast(0x80000000);

unsigned int ui = 0x01234567;
*reinterpret_cast(&ui) = 0xFF;

-------------
4. const_cast
-------------

const_cast(e)는 const 또는 volatile으로 한정된 형에서 이들을 떼어내는 변환을 수행할 수 있습니다. 이는 C++ 형 체계를 무너뜨릴 수 있으므로 신중하게 사용해야 합니다.

void lie(const int* pci)
{
int* pi = const_cast(pci);
*pi = 0;
}

int i = 1;
lie(&i); // OK

const int ci = 1;
lie(&ci); // Ouch!!


위 네 가지 중에서 dynamic_cast를 제외한 셋은 C에서 (type)expression 의 형태로 사용할 수 있었던 것인데, C++에서도 "C 스타일 캐스트 연산" 이라고 불리며 남아 있기는 합니다만, 새로 작성하는 C++ 코드에서는 C++ 스타일의 캐스트 연산을 사용하는 것이 좋습니다. 이는 어떤 종류의
변환을 프로그래머가 의도하는지 명확하게 나타내 주며, 위험할 수 있는 캐스트 연산이 코드에서 좀 더 두드러져 보이도록 하고 찾기도 쉽게 만들어주기 때문입니다.

위의 내용은 캐스트 연산에 대한 일반적인 설명인데, 좀 더 구체적인 상황에서의 적용 예를 보고 연습을 해 보시려면 GotW #17을 참조해 보시기 바랍니다.



출처 : http://funspace.org/
Posted by gsi
:

Where does a Binding find its data?

If you’ve look at much WPF Xaml you’ve probably seen bindings like this:

 

<TextBlock Text="{Binding Name" />

 

… which binds the Text property of the TextBlock to the Name property of some data object.

 

The question that begets is:  where does the data come from?  The rest of this post looks at the answer.

 

 

Properties on Binding

 

The Binding class has a few properties that provide ways to let you set the source of the data onto the Binding, depending on what works best for your situation.   Binding looks like this:

 

public class Binding : BindingBase

{

    ...

    public object Source { get; set; }

    public string ElementName { get; set; }

    public RelativeSource RelativeSource { get; set; }

    ...

}

 

 

The Source Property

 

The most straightforward way to set the source of the Binding is to use the Source property.  One of the more common ways to do that is to reference the data out of a resource dictionary:

 

<Grid>

  <Grid.Resources>

    <Int32Collection x:Key='DataSource1'>1,2,3</Int32Collection>

  </Grid.Resources>

 

  <ListBox ItemsSource='{Binding Source={StaticResource DataSource1}}' />

</Grid>

 

(This example creates a ListBox with 3 entries in it, labeled “1”, “2”, and “3”.)

 

You can be even more explicit by setting the Source directly, specifying the Binding in full Xml syntax (rather than the above markup extension syntax):

 

<Grid>

  <ListBox>

    <ListBox.ItemsSource>

      <Binding>

        <Binding.Source>

          <Int32Collection>1,2,3</Int32Collection>

        </Binding.Source>

      </Binding>

    </ListBox.ItemsSource>

  </ListBox>

</Grid>

 

You can also set the Binding.Source by referencing a static member:

 

namespace MyNamespace

{

    class MyClass

    {

        public static List<int> MyData;

        static MyClass()

        {

            MyData = new List<int>();

            MyData.Add(1);

            MyData.Add(2);

            MyData.Add(3);

        }

 

    }

}

 

 

<Page

    xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'

    xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'

    xmlns:my="clr-namespace:MyNamespace" >

 

  <ListBox ItemsSource='{Binding Source={x:Static my:MyClass.MyData}}' />

 

</Page>

 

 

The ElementName Property

 

Aside from the Binding.Source property, you can also reference your data by name, using Binding.ElementName, such as:

 

<StackPanel>

  <TextBox Name='TextBox1' />

  <Button Content='{Binding Text, ElementName=TextBox1}' />

</StackPanel>

 

(This example causes the button label to be whatever you type into the text box.)

 

 

The RelativeSource Property

 

The RelativeSource property provides a way to tell the Binding to look around where it’s used to find its source.  For example, the ‘Self’ RelativeSource binds to the object on which the Binding is placed, such as in the following (which creates a TextBlock that says “Hi”):

 

<TextBlock Tag='Hi' Text='{Binding Tag, RelativeSource={RelativeSource Self}}' />

 

As another example, the following binds the TextBlock.Text property to the Grid in its ancestry (again displaying “Hi” in this case):

 

<Grid Tag='Hi'>

 

  <Border Background='LightGray'>

    <TextBlock

         Text='{Binding Tag, RelativeSource={RelativeSource FindAncestor, AncestorType=Grid}}' />

  </Border>

 

</Grid>

 

The other two modes of a RelativeSource are TemplatedParent and PreviousData.

 

Explicit DataContext Property

 

A common way the Binding can get its source is via a DataContext property set on an element (on the element itself, not on the Binding).  For (a rather boring) example, this creates a Button that says “Click”:

 

<Button Content='{Binding}'>

  <Button.DataContext>

    <sys:String>Click</sys:String>

  </Button.DataContext>

</Button>

 

This gets more interesting and typical if you set the DataContext somewhere else, usually on the root of the page/window.  That works because the DataContext property inherits.  The following example shows that by setting the DataContext onto the root.  In this case, it is set to be an XmlDataProvider which is querying a Yahoo web service for the weather in Barrow, Alaska.  Since the DataContext inherits, Bindings throughout the page have access to it automatically.  Note also in this case that since we’re binding to XML, the Bindings are using XPath syntax.

 

<Page   

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 

    >

 

  <Page.DataContext>

    <XmlDataProvider

            Source="http://xml.weather.yahoo.com/forecastrss?p=99723" 

            XPath="/rss/channel"/>

  </Page.DataContext>

 

  <Border BorderBrush="Black"

          BorderThickness="1" Width="370" Height="170" CornerRadius="6">

    <StackPanel>

 

      <!-- Image for "Yahoo! News" -->

      <Image Margin="15,15,0,0"

                   Stretch="None" 

                   HorizontalAlignment="Left"

                   Source="{Binding XPath=image/url}" />

 

      <!-- Text to say e.g. "Yahoo! Weather - Bellevue, WA", with a hyperlink to a

           detailed weather page -->

      <TextBlock Margin="15,15,0,0">

        <Hyperlink NavigateUri="{Binding XPath=item[1]/link}">

          <TextBlock Text="{Binding XPath=title}"/>

        </Hyperlink>

      </TextBlock>

 

      <!-- Text to say e.g. "Conditions for Belleveue, WA at 9:53am ..." -->

      <TextBlock FontWeight="Bold"    Margin="15,15,0,0"

                 Text="{Binding XPath=item[1]/title}"/>

 

      <!-- Weather details  -->

      <TextBlock Margin="15,0,0,0">

 

        <!-- Text to say current condition and temp -->

        <TextBlock>

          <TextBlock.Text>

            <Binding >

              <Binding.XPath>

                item[1]/*[local-name()="condition" and

                namespace-uri()="http://xml.weather.yahoo.com/ns/rss/1.0"]/@text

              </Binding.XPath>

            </Binding>

          </TextBlock.Text>

        </TextBlock>,

        <TextBlock>

          <TextBlock.Text>

            <Binding >

              <Binding.XPath>

                item[1]/*[local-name()="condition" and

                namespace-uri()="http://xml.weather.yahoo.com/ns/rss/1.0"]/@temp

              </Binding.XPath>

            </Binding>

          </TextBlock.Text>

        </TextBlock>°

        <TextBlock>

          <TextBlock.Text>

            <Binding >

              <Binding.XPath>

                *[local-name()="units" and

                namespace-uri()="http://xml.weather.yahoo.com/ns/rss/1.0"]/@temperature

              </Binding.XPath>

            </Binding>

          </TextBlock.Text>

        </TextBlock>

        <LineBreak/>

 

        <!-- Text to say sunrise/sunset times -->

        Sunrise:

        <TextBlock>

          <TextBlock.Text>

            <Binding >

              <Binding.XPath>

                *[local-name()="astronomy" and

                namespace-uri()="http://xml.weather.yahoo.com/ns/rss/1.0"]/@sunrise

              </Binding.XPath>

            </Binding>

          </TextBlock.Text>

        </TextBlock>, sunset:

 

        <TextBlock>

          <TextBlock.Text>

            <Binding >

              <Binding.XPath>

                *[local-name()="astronomy" and

                namespace-uri()="http://xml.weather.yahoo.com/ns/rss/1.0"]/@sunset

              </Binding.XPath>

            </Binding>

          </TextBlock.Text>

        </TextBlock>

      </TextBlock>

    </StackPanel>

 

  </Border>

</Page>

 

… Sunrise at midnight, sunset at noon:

 

Attachment: barrow.jpg (11494 bytes)

 

 

Implicit DataContext

 

Finally, there are a couple of places where the DataContext gets set automatically for you.  That usually happens with ContentControl (e.g. Button) and ItemsControl (e.g. ListBox). 

 

Here’s a ContentControl example.  In this markup we have a DataTemplate set up in a ResourceDictionary so that it will be used for any ContentControl that has a String as its content.  So it’s automatically picked up in the subsequent Button.  In that DataTemplate, we have a binding to the data item, which in this case is the ContentControl.Content.  Therefore what we get here is a Button that says “Click” in bold italic.

 

<Page   

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 

    xmlns:sys="clr-namespace:System;assembly=mscorlib" >

 

  <Page.Resources>

    <DataTemplate DataType="{x:Type sys:String}">

      <!-- The Text property is bound to the Content property of

           whatever ContentControl with which this DataTemplate is used -->

      <TextBlock Text='{Binding}' FontStyle='Italic' FontWeight='Bold' />

    </DataTemplate>

  </Page.Resources>

 

  <Button>Click</Button>

 

</Page>

 

 

And here’s an ItemsControl example.  In this markup, we have a ListBox bound to an integer collection again (using the inherited DataContext as the source), but this time we have an item template, which is a  template to use when displaying the items in the ListBox.  And within that item template, the DataContext is again automatically set to be the item

 

<Page   

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

    xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml >

 

  <Page.DataContext>

    <Int32Collection>1,2,3</Int32Collection>

  </Page.DataContext>

 

  <!-- ItemsSource is bound to the DataContext (Int32Collection) -->

  <ListBox ItemsSource='{Binding}' >

    <ListBox.ItemTemplate>

      <DataTemplate>

 

        <DataTemplate.Triggers>

          <!-- Within the DataTemplate, the DataContext is set to be the data item.

               So this DataTrigger.Binding property's DataContext is going to be

               the item (1, 2, or 3) -->

          <DataTrigger Binding='{Binding}' Value='2'>

            <Setter Property='TextBlock.FontStyle' Value='Italic' />

            <Setter Property='TextBlock.FontWeight' Value='Bold' />

          </DataTrigger>

        </DataTemplate.Triggers>

 

        <Border Padding='10'>

          <!-- Similarly this Text property is bound to the item (1, 2, or 3) -->

          <TextBlock Text='{Binding}' />

        </Border>

      </DataTemplate>

    </ListBox.ItemTemplate>

  </ListBox>

</Page>

Posted by gsi
:

RectAnimation anima = new RectAnimation();
anima .From =
new Rect(100, 100, 200, 200);
anima .To =
new Rect(0, 0, 400, 400);
anima .Duration =
new Duration(TimeSpan.FromSeconds(1));
anima .AutoReverse =
true;
anima .RepeatBehavior =
RepeatBehavior.Forever;
AnimationClock clock = anima .CreateClock();
dc.DrawRectangle(
Brushes.Blue, null, new Rect(0, 0, 0, 0), clock);

Posted by gsi
:

xaml 코드에서 Completed="OnCompleted" 를 사용해서 에니메이션이 완료 되었을때 처리코드를 추가 할 수 있다.

<
Window.Resources>
  <
Storyboard x:Key="sb1" Completed="OnCompleted"
>
     <
DoubleAnimation  Storyboard.TargetName="deactiveAnimationRectangle" Storyboard.TargetProperty="Width" From="20" To="400" Duration="0:0:5"
/>
     <
DoubleAnimation Storyboard.TargetName="holdEndAnimationRectangle" Storyboard.TargetProperty="Width" From="10" To="400" Duration="0:0:1.5" BeginTime="0:0:0.5"
/>
</
Storyboard
>
</
Window.Resources
>

Being able, when animation ended, to set rectangle Width using: holdEndAnimationRectangle.Width = 250;

Also tried:

void OnCompleted (object sender, EventArgs e)
{
  Storyboard sb = (Storyboard)this.FindResource("sb1"
);
  sb.FillBehavior = FillBehavior
.Stop;
  holdEndAnimationRectangle.Width = 250;
}

Posted by gsi
: