이미 존재하는 DateTimePicker 컨트롤을 중심으로 해킹을 생성하도록 요청 받았습니다. 일반적으로 날짜/시간 선택기에는 달력의 훌륭한 이미지가 있고 그 다음에 실제 날짜를 표시하는 텍스트 상자가 있습니다. 사용자는 이미지를 클릭하고 팝업 캘린더를 표시 할 수 있으며, 선택하면 날짜가 텍스트 상자 영역으로 새로 고쳐집니다.제어 템플릿 스토리 보드, 같은 템플릿 내에서 다른 컨트롤의 값을 설정하십시오.
다른 디자이너는 일정 그래픽이 마음에 들지 않고 일반 텍스트 상자 컨트롤 만 원하지만 사용자가 두 번 클릭하여 팝업 달력을 열면 날짜를 가져 와서 새로 고칩니다. 나는 S/O에서 여기에서 찾아낸 다른 도움 덕분에 이것에 아주 가깝다.
그래서, 내 컨트롤 템플릿을 설명하고 평범한 (비 사용자 지정 컨트롤을 제안하지 않는 한)로 유지. 컨트롤 템플릿은 텍스트 상자 컨트롤을 기반으로합니다. 우리는 텍스트 상자의 PART_ContentHost와 테두리를 가지고 표준 달력 컨트롤의 팝업을 가지고 있습니다.
컨트롤 템플릿 트리거의 경우, ScrollViewer (텍스트 입력 영역)에 연결된 MouseDoubleClick 이벤트가 있습니다. 방아쇠되었을 경우, 팝업의 IsOpen을 true로 설정해, 달력을 공개합니다. 이것은 잘 작동합니다.
이제 끝내십시오. 사용자가 달력에서 날짜를 선택하면 다음 트리거가 팝업을 닫습니다 (IsOpen을 false로 설정). 이것도 작동합니다.
내 문제. 또한 선택한 날짜를 가지고 자사의 ToString() 날짜 표현이 ScrollViewer.Content (X : 이름 = "PART_ContentHost)에 넣어 얻을 선택에 따라 할 수 있습니다.
<ControlTemplate TargetType="{x:Type TextBox}" x:Key="CTTextBox" >
<StackPanel>
<Border x:Name="targetBorder"
BorderBrush="{TemplateBinding BorderBrush}"
SnapsToDevicePixels="true">
<ScrollViewer x:Name="PART_ContentHost"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
Foreground="{TemplateBinding Foreground}" />
</Border>
<Popup PlacementTarget="{Binding ElementName=PART_ContentHost}" x:Name="PopCal">
<Calendar x:Name="ActualCalendar"/>
</Popup>
</StackPanel>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="ScrollViewer.MouseDoubleClick" SourceName="PART_ContentHost">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames
Storyboard.TargetName="PopCal"
Storyboard.TargetProperty="(Popup.IsOpen)">
<DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Calendar.SelectedDatesChanged" SourceName="ActualCalendar">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames
Storyboard.TargetName="PopCal"
Storyboard.TargetProperty="(Popup.IsOpen)">
<DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
WHAT WOULD I PUT HERE to have the selected date of the popup calendar
inserted into the content of the PART_ContentHost...
<Storyboard>
<BooleanAnimationUsingKeyFrames
Storyboard.TargetName="PART_ContentHost"
Storyboard.TargetProperty="(Content)">
<DiscreteBooleanKeyFrame KeyTime="00:00:00" Value=" ????? "/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style TargetType="{x:Type TextBox}" x:Key="STextBox" >
<!--<Setter Property="OverridesDefaultStyle" Value="True"/>-->
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Height" Value="20" />
<Setter Property="Width" Value="100" />
<Setter Property="VerticalContentAlignment" Value="Bottom" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="HorizontalAlignment" Value="Left" />
<!-- Padding is Left, Top, Right, Bottom -->
<Setter Property="Padding" Value="2,0,0,2" />
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="Visibility" Value="Visible" />
<Setter Property="IsEnabled" Value="True" />
<Setter Property="CharacterCasing" Value="Upper" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="Background" Value="White" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="Template" Value="{StaticResource CTTextBox}" />
</Style>
몇 가지 좋은 점을 지적하고 클래스 정의에 대한 다른 대안을 가지고 있습니다 ... – DRapp
@DRapp : 왜 클래스 정의에 대한 대안을 찾고 있습니까? 나를 위해, 클래스의 동작은 독립적입니다, 그것은 단지 하나의 네임 스페이스에 있습니다. –
우리가 적용해야 할 물건의 프레임 워크에 다른 기본 요소가 있기 때문에 수업을 통해 처리하고 있습니다. 나는 그것을 거기에 놓았을 것이고, 내가 여기에서 여러분의 피드백을 기반으로 대부분을 감쌌다 고 생각합니다. 감사 – DRapp