2014-05-15 5 views
3

DisplayMode="Year"this.DataContext = new SampleModel();에있는 캘린더를 사용하고 있으므로 모델의 속성에 액세스 할 수 있습니다. XAML : 그러나 달력 (스크린 샷 참조)Xaml Calendar DisplayMode = GridDefinitions 및 DataContext와 함께 사용할 때 "Year"가 작동하지 않습니다.

코드가 내려 오는 잘못된 렌더링 뒤에

<Window x:Class="Excel2.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="600" Width="800"> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="250"></ColumnDefinition> 
      <ColumnDefinition Width="2*"></ColumnDefinition> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="220"></RowDefinition> 
      <RowDefinition Height="*"></RowDefinition> 
     </Grid.RowDefinitions> 

     <Calendar DisplayMode="Year"></Calendar> 
    </Grid> 
</Window> 

코드 :

using .... 

namespace Excel2 
{ 
    class SampleModel 
    { 
    } 

    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     {    
      InitializeComponent(); 
      this.DataContext = new SampleModel(); 
     } 
    } 
} 

결과 : XAML calender Displaymode=Year error 당신이 볼 수 있듯이, 캘린더는 년 정보를 보여주지 않고 렌더링됩니다.

격자 정의를 사용하지 않으면 Displaymode=Year 또는 this.DataContext =... 모든 것이 올바르게 렌더링됩니다.

XAML의 버그입니까?

답변

2

이 질문은 1 년 넘게 물어 왔으며 여전히 받아 들여지지 않은 답변이므로이 버그를 어떻게 없애고 싶습니다.

내가 내 XAML을 변경 :

<Calendar Grid.Row="0" Grid.Column="3" x:Name="_calendar" DisplayModeChanged="_calendar_DisplayModeChanged" Loaded="_calendar_OnLoaded" 
          DisplayDate="{Binding SelectedMonth, UpdateSourceTrigger=PropertyChanged}" DisplayMode="Month" /> 

//Setting DisplayMode="Month" in xaml and will change it back to "Year" in code behind. so my codebehind code is 


    private void _calendar_DisplayModeChanged(object sender, CalendarModeChangedEventArgs e) 
    { 
     _calendar.DisplayMode = CalendarMode.Year; 
    } 

    private void _calendar_OnLoaded(object sender, RoutedEventArgs e) 
    { 
     _calendar.DisplayMode = CalendarMode.Year; 
    } 

로드 이벤트가 선택 변경이있을 때 후속 호출에 변경하는 데 필요한 년도 및 DisplayModeChanged 이벤트에 처음으로 디스플레이 모드를 변경해야합니다.

앞으로 도움이되기를 바랍니다.

+0

왜이 답변을위한 upvote가 없었는지 이해가 안됩니다. 나는이 달 피 크커를 성취하기 위해 고심하고 있었고 당신은 일하는 해결책을 가진 유일한 사람이었습니다 ... 고마워요! – Speuline

+1

다행스럽게도 @Speuline –

+0

잠시 시간이 있으면 코드에 또 다른 문제가 있습니다. http://stackoverflow.com/questions/40491255/issue-monthpicker-size-with-mvvm-light-toolkit – Speuline