2010-04-26 3 views
1

C#/WPF 프로젝트에 캘린더가 필요합니다. 우리는 약속 스케줄링을 위해 일정 범위의 날짜를 선택하기 위해이를 사용할 것입니다. 기본 캘린더가 일부 담당자에게 사용하기에는 너무 작아서 크기 조정 작업을하고 있다고 들었습니다.내 스타일의 제어 템플릿이 내 캘린더의 사용 제한 시간을 초과합니다.

<toolkit:Calendar Grid.Row="1" x:Name="DateWindowCalendar" 
    BorderBrush="White" BorderThickness="0" 
    Style="{StaticResource PopupCalendarStyle}" 
    DisplayMode="Month" SelectionMode="SingleRange" 
    DisplayDateStart="{Binding FirstDayOfMonth}" 
    AutomationProperties.AutomationId="ToolkitCalendarId" 
    VerticalAlignment="Top"> 
</toolkit:Calendar> 

은 내가이 스타일을 만들었습니다

<Style x:Key="PopupCalendarStyle" TargetType="toolkit:Calendar"> 
    <Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="toolkit:Calendar"> 
     <StackPanel Margin="0" HorizontalAlignment="Center" x:Name="Root"> 
      <toolkit:Calendar x:Name="Calendar" 
      SelectedDate="{TemplateBinding SelectedDate}" 
      DisplayDateStart="{TemplateBinding DisplayDateStart}" 
      SelectionMode="{TemplateBinding SelectionMode}" 
      Background="{TemplateBinding Background}" 
      BorderBrush="{TemplateBinding BorderBrush}" 
      BorderThickness="{TemplateBinding BorderThickness}" 
      SelectedDatesChanged="Calendar_SelectedDatesChanged"> 

      <toolkit:Calendar.CalendarDayButtonStyle> 
       <Style> 
       <Setter Property="Button.Height" Value="34"/> 
       <Setter Property="Button.Width" Value="34" /> 
       <Setter Property="Button.FontSize" Value="16" /> 
       </Style> 
       </toolkit:Calendar.CalendarDayButtonStyle> 

       <toolkit:Calendar.CalendarButtonStyle> 
       <Style> 
        <Setter Property="Button.Height" Value="34"/> 
        <Setter Property="Button.Width" Value="34"/> 
        <Setter Property="Button.FontSize" Value="16"/> 
       </Style> 
       </toolkit:Calendar.CalendarButtonStyle> 

      </toolkit:Calendar> 
      </StackPanel> 
     </ControlTemplate> 
     </Setter.Value> 
    </Setter>    
    </Style> 

모든 것이 거의 완벽합니다. 내 범위를 지정하면 선택한 날짜를 추적 할 수 있습니다 (SelectedDates 속성 대신 SelectedDatesChanged 이벤트를 사용하여 부여됨).

문제는 또한 정전 날짜를 설정할 수 있어야합니다. .

DateWindowCalendar.BlackoutDates.Add(new CalendarDateRange(
    new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01), DateTime.Now)); 

을하지만 스타일을 추가 할 때, 나는있는 표시를 검은 색을 얻을하지 않습니다 : 오늘 때로는 먼저 지금부터 몇 일 월)

의 스타일없이,이 작동하지만, 표시되며 더 이상 블랙 아웃 날짜를 선택할 수 없습니다.

내가 무엇을 놓쳤는 지 잘 모르겠지만 누군가가 쉬운 대답을하기를 바라고 전체 위젯을 다시 만들 필요가 없다.

도움을 주시면 감사하겠습니다.

감사합니다,

크리스 당신이 존중되는 곳 내가 볼 수없는 당신의 스타일에

답변

1

좋아 ... 그게 아니었다 그러나 나는 다음 사람이 대답을 떠날거야.

첫 번째 BlackoutDates는 읽기 전용 범위 모음의 무서운 묘미입니다. 꽤 많이 바인딩 할 수 없습니다. 나는 위젯을 다시 쓰면서 훑어 보았지만 그다지 멀지 않았다.

나는 뭔가를 찾았습니다. 코드에서 블랙 아웃 범위를 설정할 수 있습니다.

그러나 건설 중에이 작업을 수행하면 템플릿을 통과하지 못합니다. 이유는 확실하지 않습니다. 따라서 캘린더를 만든 다음 작동하는 블랙 아웃 범위를 설정하면됩니다. 그러나 캘린더 스타일을 지정할 때 템플릿 바인딩이 없습니다 (바인딩 할 수없는 종속성 속성이 아니기 때문에).

그러나 스타일에 의해 생성 된 이벤트를 통해 BlackoutDates를 설정하면 날짜가 설정되는 것처럼 보입니다. 그 일을 통해이 나를 스타일 달력에 BlackoutDates 설정할 수로드 처리기를 만드는 데 매우 사소한했다

  <Style x:Key="PopupCalendarStyle" TargetType="toolkit:Calendar"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="toolkit:Calendar"> 
         <StackPanel Margin="0" HorizontalAlignment="Center" x:Name="Root"> 
          <toolkit:Calendar x:Name="Calendar" 
               SelectedDate="{TemplateBinding SelectedDate}" 
               DisplayDateStart="{TemplateBinding DisplayDateStart}" 
               SelectionMode="{TemplateBinding SelectionMode}" 
               Background="{TemplateBinding Background}" 
               BorderBrush="{TemplateBinding BorderBrush}" 
               BorderThickness="{TemplateBinding BorderThickness}" 
               SelectedDatesChanged="Calendar_SelectedDatesChanged" 
               **Loaded="Calendar_Loaded"**> 
           <toolkit:Calendar.CalendarDayButtonStyle> 
            <Style> 
             <Setter Property="Button.Height" Value="34"/> 
             <Setter Property="Button.Width" Value="34" /> 
             <Setter Property="Button.FontSize" Value="16" /> 
            </Style> 
           </toolkit:Calendar.CalendarDayButtonStyle> 
           <toolkit:Calendar.CalendarButtonStyle> 
            <Style> 
             <Setter Property="Button.Height" Value="34"/> 
             <Setter Property="Button.Width" Value="34"/> 
             <Setter Property="Button.FontSize" Value="16"/> 
            </Style> 
           </toolkit:Calendar.CalendarButtonStyle> 
          </toolkit:Calendar> 
         </StackPanel> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter>    
     </Style> 

:

 private void Calendar_Loaded(object sender, RoutedEventArgs e) 
    { 
     ((Calendar)sender).BlackoutDates.Add(new CalendarDateRange(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01), DateTime.Now)); 
    } 
을 나는 그래서로드 이벤트를 사용
1

"정전 날짜를." 기본 스타일은 어떤 모습입니까? 기본 스타일에는 BlackoutDates 컬렉션에 바인딩되는 블랙 아웃 날짜라고하는 Calendar 컨트롤의 특성이 있다고 가정합니다. 이 같은

뭔가 :

<Style x:Key="PopupCalendarStyle" TargetType="toolkit:Calendar"> 
     <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="toolkit:Calendar"> 
      <StackPanel Margin="0" HorizontalAlignment="Center" x:Name="Root"> 
       <toolkit:Calendar x:Name="Calendar" 
       SelectedDate="{TemplateBinding SelectedDate}" 
       DisplayDateStart="{TemplateBinding DisplayDateStart}" 
       BlackoutDates="{TemplateBinding BlackoutDates}" 
       SelectionMode="{TemplateBinding SelectionMode}" 
       Background="{TemplateBinding Background}" 
       BorderBrush="{TemplateBinding BorderBrush}" 
       BorderThickness="{TemplateBinding BorderThickness}" 
       SelectedDatesChanged="Calendar_SelectedDatesChanged"> 

       <toolkit:Calendar.CalendarDayButtonStyle> 
        <Style> 
        <Setter Property="Button.Height" Value="34"/> 
        <Setter Property="Button.Width" Value="34" /> 
        <Setter Property="Button.FontSize" Value="16" /> 
        </Style> 
        </toolkit:Calendar.CalendarDayButtonStyle> 

        <toolkit:Calendar.CalendarButtonStyle> 
        <Style> 
         <Setter Property="Button.Height" Value="34"/> 
         <Setter Property="Button.Width" Value="34"/> 
         <Setter Property="Button.FontSize" Value="16"/> 
        </Style> 
        </toolkit:Calendar.CalendarButtonStyle> 

       </toolkit:Calendar> 
       </StackPanel> 
      </ControlTemplate> 
      </Setter.Value> 
     </Setter>    
     </Style> 
관련 문제