« Previous : 1 : 2 : 3 : 4 : 5 : ... 56 : Next »

참조 : http://blogs.msdn.com/llobo/archive/200 ··· ing.aspx

만약 여러분이 실버라이트에 익숙하다면 새로운 것은 없습니다. 이 속성 FrameworkElement에 새로이 추가가 되었었는데 각 길이를 반올림 하는 기능입니다. 기본 값은 실버라이트와 다르게 False이며 값을 설정하게 되면 자식 요소에 상속 됩니다. 이 속성을 설정한 것과 설정하지 않은 것은 다음과 같이 차이를 볼 수 있습니다.

사용자 삽입 이미지

예제 코드는 다음과 같습니다.

사용자 삽입 이미지

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/12/30 17:25 2009/12/30 17:25
Posted by 나는산.
TAGS

Leave your greetings here.

[로그인][오픈아이디란?]
참조 : http://blogs.msdn.com/llobo/archive/200 ··· ogs.aspx

기존 OpenFileDialog나 SaveFileDialog가 XP 스타일 이였던 것을 Windows Vista/7 스타일로 수정되었습니다.

기존에는 다음과 같았으나,

사용자 삽입 이미지
다음과 같이 변경되었습니다.

사용자 삽입 이미지



크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/12/30 16:02 2009/12/30 16:02
Posted by 나는산.
TAGS

Leave your greetings here.

[로그인][오픈아이디란?]

참조 : http://blogs.msdn.com/llobo/archive/200 ··· ons.aspx

Easing 함수들은 여러분들의 애니메이션들에 사용자 정의 수학 방정식들을 추가할 수 있게 해줍니다. 이런 사용자 정의 수학 방정식들을 이용하면 애니매이션들은 더 실제와 같거나 부드럽습니다. WPF 4에서는 이런 사용자 정의 수학 방정식 11개가 미리 정의 되어 있습니다. 이들 각 함수들은 3개의 모드(EaseIn, EaseOut, EaseInOut)를 가집니다.

이번 WPF 4에서 기존에 있었거나 새롭게 추가된 애니매이션 관련 클래스들 - ByteAnimation, ColorAnimation, DecimalAnimation, DoubleAnimation, Int16Animation, Int32Animation, Int64Animation, Point3DAnimation, PointAnimation, QuaternionAnimation, RectAnimation, Rotation3DAnimation, SingleAnimation, SizeAnimation, ThicknessAnimation, Vector3DAnimation, VectorAnimation 등 - 전반적으로 EasingFunction 속성이 추가되었다. 이 속성은 IEasingFunction이라는 인터페이스로 정의 되어 있으며, 이것은 개발자에게 다양한 효과를 애니메이션에 적용할 수 있도록 만들수 있도록 해줍니다.

IEasingFunction에 대해서 더 자세하게 얘기하자면 0과 1사이의 정규화된 시간에 각각 값을 반환할 수 있는 함수를 만들 수 있도록 해준다. 쉽게 얘기하면 0은 애니메이션이 시작하는 값이고 1은 애니메이션이 끝나는 값을 가리킵니다.

WPF 4에서는 IEasingFunction을 상속받아 미리 정의해놓은 클래스가 11개가 있다고 했습니다. 이들은 클래스는 공통적으로 System.Windows.Media.Animation.EasingFunctionBase 클래스를 상속합니다. 대부분 미리 정의해 놓은 EasingFunction을 사용하지 않고 사용자가 직접 개발한다면 이 클래스를 상속 받아 사용합니다. EaseInCore 함수를 오버라이드 하여 작성하면 되는데 다음과 같이 하면 됩니다.

namespace CustomEasingFunction
{
    public class CustomSeventhPowerEasingFunction : EasingFunctionBase
    {
        public CustomSeventhPowerEasingFunction()
            : base()
        {
        }

        // Specify your own logic for the easing function by overriding

        // the EaseInCore method. Note that this logic applies to the "EaseIn"

        // mode of interpolation. 

        protected override double EaseInCore(double normalizedTime)
        {
            // applies the formula of time to the seventh power.

            return Math.Pow(normalizedTime, 7);
        }

        // Typical implementation of CreateInstanceCore

        protected override Freezable CreateInstanceCore()
        {

            return new CustomSeventhPowerEasingFunction();
        }

    }
}

EasingFunctionBase는 EasingMode 속성을 가지고 있습니다. EasingMode는 다음과 같이 3가지 모드가 있습니다.
- EaseIn : 기본 EaseInCore 구현대로 작동됩니다.
- EaseOut : 기본 EaseInCore와 반대로 작동됩니다. (X, Y좌표 -1 곱한값)
- EaseInOut : EaseIn 실행후 EaseOut 실행됩니다.

미리 정의해놓은 EasingFunction은 다음과 같습니다.

사용자 삽입 이미지

사용자 삽입 이미지

사용자 삽입 이미지

결론적으로 어떻게 보면 기존 Spline 사용하는 것을 더 넓게 적용, 더 자세하게 제어할 수 있게 되었다고 생각하면 될 것 같습니다.
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/12/30 15:40 2009/12/30 15:40
Posted by 나는산.
TAGS

Leave your greetings here.

[로그인][오픈아이디란?]

참조 : http://blogs.msdn.com/llobo/archive/200 ··· ush.aspx

WPF 4 부터는 TextBoxBase를 상속 받는 RichTextBox와 TextBox 컨트롤와 PasswordBox 컨트롤에 새로운 속성인 CaretBrush, SelectionBrush 그리고 SelectionOpacity가 추가되었다.

이전 버전에서는 텍스트 선택 색상과 투명도를 조절할 수 없었으며, 현재 커서 색상을 수정할 수 없었습니다. WPF4 부터는 텍스트 선택 부분을 개발자가 Brush로 설정하거나 텍스트 선택 부분의 투명도를 설정할 수 있습니다. 또, 현재 커서도 개발자가 Brush로 설정할 수 있습니다.

CaretBrush는 현재 커서의 표시를 Brush로 설정하거나 가져옵니다.
SelectionBrush는 현재 선택 부분의 표시를 Brush로 설정하거나 가져옵니다.
SelectionOpacity는 현재 선택 부분의 표시의 투명도를 설정하거나 가져옵니다.

사용자 삽입 이미지

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/12/30 14:47 2009/12/30 14:47
Posted by 나는산.
TAGS

Leave your greetings here.

[로그인][오픈아이디란?]

POSTSHARP 소개

2009/12/29 10:25 / Programming/.NET
사이트 : http://www.postsharp.org/

PostSharp은 여러분의 .NET 코드의 라인수를 줄이고, 논리적은 관계를 분리시켜 코드를 작성할 수 있도록 해줍니다.

쉽게 얘기하면 일반화할 수 있는 코드를 Attribute로 작성할 수 있습니다.

몇가지 예를 들겠습니다.

(1) Trace : 트래이스할 수 있는 사용자 정의 Attribute

public class TraceAttribute : OnMethodBoundaryAspect
{ 
  public override void OnEntry( MethodExecutionEventArgs eventArgs) 
  { Trace.TraceInformation("Entering {0}.", eventArgs.Method);  }

  public override void OnExit( MethodExecutionEventArgs eventArgs)
  { Trace.TraceInformation("Leaving {0}.", eventArgs.Method);   }
}



(2) Async : 특정 함수를 비동기로 만드는 사용자 정의 Attribute

public class AsyncAttribute : OnMethodInvocationAspect
{
  public override void OnInvocation(MethodInvocationEventArgs eventArgs)
  {
    ThreadPool.QueueUserWorkItem(delegate { eventArgs.Proceed(); });
  }
}



(3) GUI Dispatch : 특정 함수를 GUI 쓰레드에서 실행하게 하는 사용자 정의 Attribute

public class GuiThreadAttribute : OnMethodInvocationAspect
{
  public override void OnInvocation(MethodInvocationEventArgs eventArgs)
  {
    DispatcherObject dispatcherObject = (DispatcherObject)eventArgs.Delegate.Target;

    if (dispatcherObject.CheckAccess())
      eventArgs.Proceed();
    else
      dispatcherObject.Dispatcher.Invoke( DispatcherPriority.Normal,
                                          new
Action(() => eventArgs.Proceed()));
  }
}


(4) Exception : 예외를 처리하는 사용자 정의 Attribute

public class ExceptionDialogAttribute : OnExceptionAspect
{
  public override void OnException(MethodExecutionEventArgs eventArgs)
  {
    string message = eventArgs.Exception.Message;
    Window window = Window.GetWindow((DependencyObject) eventArgs.Instance);
    MessageBox.Show(window, message, "Exception");
   
eventArgs.FlowBehavior = FlowBehavior.Continue;
  }

}



(5) Cache : 캐쉬를 하는 사용자 정의 Attribute

public class CacheAttribute : OnMethodInvocationAspect
{
    public override void OnInvocation(MethodInvocationEventArgs eventArgs)
    {
        object value;
        string key = // Compute the cache key (details omitted).

        if (!cache.TryGetValue(key, out value))
        {
            lock ( this )
            {
                if (!cache.TryGetValue(key, out value))
                {  
                    eventArgs.Proceed();
                    value = eventArgs.ReturnValue;
                    cache.Add(key, value);
                    return;
                }
            }
        }
        eventArgs.ReturnValue = value;
    }
}

저는 실제로 INotifyPropertyChanged를 구현할때 일일히 속성을 정의하는게 귀찮아서
어떻게 Attribute로 할 수 없을까 구글로 검색했는데 PostSharp를 사용하면 쉽게 할수 있었습니다.

http://code.google.com/p/propfu/


윈래 이런 코드가

public class PersonLame : INotifyPropertyChanged
   
{
       
private string _name;
       
public string Name
       
{
           
get { return _name; }
           
set
           
{
               
if (value == _name)
                   
return;

                _name
= value;
               
OnPropertyChanged("Name");
           
}
       
}

       
private int _age;
       
public int Age
       
{
           
get { return _age; }
           
set
           
{
               
if (value == _age)
                   
return;

                _age
= value;
               
OnPropertyChanged("Age");
           
}
       
}

       
#region INotifyPropertyChanged Members

       
public event PropertyChangedEventHandler PropertyChanged;

       
#endregion

       
private void OnPropertyChanged(string propertyName)
       
{
           
if (PropertyChanged == null)
               
return;

           
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
       
}
   
}

다음 코드로 정리 됩니다.


[NotifyPropertyChanged]
   
public class PersonAwesome : INotifyPropertyChanged
   
{
       
public string Name { get; set; }

       
public int Age { get; set; }

       
#region INotifyPropertyChanged Members

       
public event PropertyChangedEventHandler PropertyChanged;

       
#endregion

       
[OnPropertyChanged]
       
private void OnPropertyChanged(string propertyName)
       
{
           
if (PropertyChanged == null)
               
return;

           
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
       
}
   
}
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/12/29 10:25 2009/12/29 10:25
Posted by 나는산.
TAGS , , ,

Leave your greetings here.

[로그인][오픈아이디란?]

To install subversion, open a terminal and run the following command:

sudo apt-get install apache2
sudo apt-get install subversion libapache2-svn

We’re going to create the subversion repository in /svn, although you should choose a location that has a good amount of space.

sudo svnadmin create /svn
sudo chown www-data:www-data /svn -R

Next we’ll need to edit the configuration file for the subversion webdav module. You can use a different editor if you’d like.

sudo gedit /etc/apache2/mods-enabled/dav_svn.conf

The Location element in the configuration file dictates the root directory where subversion will be acessible from, for instance: http://www.server.com/svn

<Location /svn>

The DAV line needs to be uncommented to enable the dav module

# Uncomment this to enable the repository,
DAV svn

The SVNPath line should be set to the same place your created the repository with the svnadmin command.

# Set this to the path to your repository
SVNPath /svn

The next section will let you turn on authentication. This is just basic authentication, so don’t consider it extremely secure. The password file will be located where the AuthUserFile setting sets it to…  probably best to leave it at the default.

# Uncomment the following 3 lines to enable Basic Authentication
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /etc/apache2/dav_svn.passwd

To create a user on the repository use, the following command:

sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd <username>

Note that you should only use the -c option the FIRST time that you create a user. After that you will only want to use the -m option, which specifies MD5 encryption of the password, but doesn’t recreate the file.

Example:

sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd geek
New password:
Re-type new password:
Adding password for user geek

Restart apache by running the following command:

sudo /etc/init.d/apache2 restart

Now if you go in your browser to http://www.server.com/svn, you should see that the repository is enabled for anonymous read access, but commit access will require a username.

If you want to force all users to authenticate even for read access, add the following line right below the AuthUserFile line from above. Restart apache after changing this line.

Require valid-user

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/12/02 21:53 2009/12/02 21:53
Posted by 나는산.

Leave your greetings here.

[로그인][오픈아이디란?]
참조 : http://modeeb.wordpress.com/2009/04/08/c-40-whats-next/

Improved COM Interoperability

C#에서 COM interop 함수들과 작업을 했을때, 여러분은 다음과 같이 불필요한 파라미터에 참조값으로 Missing.Value를 넘겨줬어야 했다.

object filename = "test.docx";
object missing = System.Reflection.Missing.Value;

doc.SaveAs(ref filename,
           ref missing, ref missing, ref missing,
           ref missing, ref missing, ref missing,
           ref missing, ref missing, ref missing,
           ref missing, ref missing, ref missing,
           ref missing, ref missing, ref missing);

인제 C# 4.0에서는 다음과 같이 코딩하면 된다.

doc.SaveAs(filename);

위 코드를 보면 여러분은 ref 생략이 가능하지만, 아직 COM interoperability를 사용하지 않을 경우 ref를 생략하면 안된다. 또, 여러분의 .NET 응용프로그램과 Primary Interop Assembly (PIA)를 포함되어야 했다. C# 4.0에서는 이 작업이 필요없다.
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/12/01 13:01 2009/12/01 13:01
Posted by 나는산.
TAGS

Leave your greetings here.

[로그인][오픈아이디란?]
참조 : http://modeeb.wordpress.com/2009/04/08/c-40-whats-next/

Optional and Named Parameters

C# 4.0의 또 다른 장점은 C나 C++처럼 Optional Paramenter와 Named Parameter를 지원한다는 것이다.

이전 C#에서는 이런 기능들이 지원이 되지 않아 함수 이름이 똑같지만 파라미터가 다른 여러개의 함수들을 볼 수 있었을 것이다. C# 4.0에서는 다음과 같이 함수는 선택적 파라미터를 사용하여 리펙토링 될 수 있다.

public StreamReader OpenTextFile(
         string path,
         Encoding encoding = null,
         bool detectEncoding = false,
         int bufferSize = 1024) { }

위와 같이 OpenTextFile 함수는 선택적 파라미터 하나 이상의 파라미터를 생략해서 사용할 수 있다.

OpenTextFile("foo.txt", Encoding.UTF8);

또한 C# 4.0는 Named Parameter를 지원해서 OpenTextFile 함수는 선택적 파라미터를 생략하면서 특정 파마리터를 정의해서 사용할 수 있다.

OpenTextFile("foo.txt", Encoding.UTF8, bufferSize: 1024);

Named Parameter는 함수 파라미터 순서에서 항상 마지막에서 사용되어야 하지만 Named Parameter 끼리는 순서가 상관 없다.
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/12/01 12:46 2009/12/01 12:46
Posted by 나는산.
TAGS

Leave your greetings here.

[로그인][오픈아이디란?]
참조 : http://modeeb.wordpress.com/2009/04/08/c-40-whats-next/

Dynamically Typed Objects

오늘날 C#에서 여러분은 아래 코드와 같이 특정 클래스의 인스턴스를 가져와서 그 인스턴스의 Add이라는 함수를 호출해서 두 정수의 합을 가져와야 하는 필요하가 있을 수도 있다.

Calculator calc = GetCalculator();
int sum = calc.Add(10, 20);

위의 코드는 만약은 Calculator 클래스가 정적 타입이 아니라 COM, Ruby, Python 아니면 심지어 JavaScript으로 쓰져 있다면 더 재미있어 진다. 우리가 Calculator 클래스가 .NET 객체라고 알고 있지만 정확하게 어떤 타입인지 몰라도 우리는 Reflection을 이용하여 런타임일 때의 속성 타입을 알수 있고 Add 함수를 동적으로 호출할 수 있다.

object calc = GetCalculator();
Type type = calc.GetType();
object result = type.InvokeMember(
         "Add",
         BindingFlags.InvokeMethod,
         null,
         new object[] { 10, 20 });
int sum = Convert.ToInt32(result);

C# 4.0에서는 다음 처럼 간단하게 코딩할 수 있다.

dynamic calc = GetCalculator();
int sum = calc.Add(10, 20);

위 코드 예제에서 우리는 dynamic이라는 정적 타입을 가지는 calc라는 변수를 선언했다. 다음에 Add 함수를 동적으호 호출하여, 호출되는 결과가 동적으로 정적 타입 정수로 변환한다.

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/12/01 12:33 2009/12/01 12:33
Posted by 나는산.
TAGS

Leave your greetings here.

[로그인][오픈아이디란?]
When we want to declaratively use our custom controls or reference the types we defined in XAML, we should declare the XML namespace to map to the CLR namespace in which the controls and types are defined as the following XAML snippt demonstrates:

<Page x:Class="Test.MainWindow"
         xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:cc
="clr-namespace:Sheva.Windows.Controls;assembly=AvalonLib"
/>

    Recently, I am heavily engaged with writing a resuable WPF control library, and quite often I need to create some pages to test those controls I create, so ever now and then I have to use the cumbersome syntax like above to declare the XML namespace, personally I don't like the syntax, and I thought Microsoft WPF team should come up with a more elegant way of doing it, and in actuality, they did introduce an alternative to do it since the CTP releases. there is a custom attribute called XmlnsDefinitionAttribute in the System.Windows.Markup namespace which allows you to apply to the assembly which contains the types and controls the XAML code would reference.the built-in WPF assemblies such as WindowsBase.dll, PresentationCore.dll, and PresentationFramework.dll all have this attribute applied, and all have http://schemas.microsoft.com/winfx/2006/xaml/presentation namespace mapped with the CLR namespaces introduced by them. and of cause you can use this attribute in your own project, just open the AssemblyInfo.cs file, and append the following directive:

[assembly: XmlnsDefinition("http://schemas.sheva.com/wpf/", "Sheva.Windows.Controls")]

    Then you can declare the namespace alias in XAML this way:

<Page x:Class="Test.MainWindow"
         xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:cc
="http://schemas.sheva.com/wpf/"
/>
   
    Wow, this is a bit like the built-in xmlns declaration indeed, really really cool indeed:)
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/11/25 12:15 2009/11/25 12:15
Posted by 나는산.
TAGS

Leave your greetings here.

[로그인][오픈아이디란?]
« Previous : 1 : 2 : 3 : 4 : 5 : ... 56 : Next »