2013-05-06 1 views
10

처음보기를 열 때보기의 기본 크기를 설정해야하지만보기에서 사용자가보기를 확장해야합니다. (다른 이유로 저는 WindowManager에서 SizeToContent 속성을 사용할 수 없습니다.)Caliburn.micro에서 초기 창 크기 설정

기본 창 크기를 설정하는 데 권장되는 방법은 무엇입니까? 이 권장되는 접근 방식 대신 부트 스트랩의/당신은/A UserControl 부트 스트랩 수 등 Window 대신 다음 설정 높이, 폭, 보여 보여주는 경우

+0

당신이보기에 특정 크기를 설정하면 나는이 작업을 볼 수있는 유일한 방법은, 보기가로드 된 후 크기를 auto로 설정하여보기를 해제하십시오. 이때 창의 크기가 내용에 맞는 크기인지 확인하십시오. – Charleh

답변

7

이 실제로 저를 도청 한 무언가이다 동안. 일단 내가 알아 냈어, 내가 그걸 빨리 알아 내지 못했어.

caliburn에 창을 표시 할 때 Window 개체를 호출 할 때 특성을 설정할 수 있습니다.

public class ShellViewModel : PropertyChangedBase, IShell 
{ 
    private readonly IWindowManager windowManager; 

    public ShellViewModel() 
    { 
     this.windowManager = new WindowManager(); 
     this.windowManager.ShowWindow(new LameViewModel()); 
    } 
} 

이 두 가지가 있습니다,이 같은 뭔가

먼저 시작할 것 :

그래서, 당신은 600 × 300 창에 높이와 너비를 설정하려는 말할 수 ShowWindow 메서드의 다른 필드 세 번째 매개 변수를 사용하면 Window 객체의 속성을 동적으로 설정할 수 있습니다.

public class ShellViewModel : PropertyChangedBase, IShell 
{ 
    private readonly IWindowManager windowManager; 

    public ShellViewModel() 
    { 
     this.windowManager = new WindowManager(); 

     dynamic settings = new ExpandoObject(); 
     settings.Height = 600; 
     settings.Width = 300; 
     settings.SizeToContent = SizeToContent.Manual; 

     this.windowManager.ShowWindow(new LameViewModel(), null, settings); 
    } 
} 

나는 문서에서이 작업에 대한 자세한 정보가 있었다 좋겠지 만, 거기 당신은 그것이있다.

+2

다른 설정을 추가해야 할 수도 있습니다 :'SizeToContent = SizeToContent.Manual'. – Govert

+0

확인되었습니다. 업데이트되었습니다. – GrantByrne

3

이 게시물이 작성되었을 때이 내용이 적용되는지 잘 모르겠지만 다음은 누구나 쉽게 응용 프로그램 부트 스트 래퍼에서 CaliburnMicro의 창 크기를 설정할 수있는 방법입니다. 내 코드는 이전에 닫은 상태에서 시작할 때와 동일한 창 크기를 유지하도록 설계되었습니다. 내가 화면 높이/너비를 폐쇄에 대한 속성을 설정으로 저장하고 여기서 시작시 다시 검색합니다 (현재 화면 크기보다 크지 않도록 확인).

AppBootstrapper.cs

다음
 protected override void OnStartup(object sender, System.Windows.StartupEventArgs e) { 

     double width = Settings.Default.screen_width; //Previous window width 
     double height = Settings.Default.screen_height; //Previous window height 

     double screen_width = System.Windows.SystemParameters.PrimaryScreenWidth; 
     double screen_height = System.Windows.SystemParameters.PrimaryScreenHeight; 

     if (width > screen_width) width = (screen_width - 10); 
     if (height > screen_height) height = (screen_height-10); 

     Dictionary<string, object> window_settings = new Dictionary<string, object>(); 

     window_settings.Add("Width", width); 
     window_settings.Add("Height", height); 

     DisplayRootViewFor<IShell>(window_settings); 
    } 
2

휴의 답변에 따라 답변입니다 :

 Dictionary<string, object> window_settings = new Dictionary<string, object>(); 
     window_settings.Add("WindowState", System.Windows.WindowState.Maximized); 

     DisplayRootViewFor<IShellViewModel>(window_settings);