我想在图像点击时填充日历控件并将该值绑定到wpf中的文本块。
<Image Name="imgCalendar" Width="20" Height="30" Source="/Images/Cal.jpg" KeyDown="imgCalendar_KeyDown" />
<TextBlock Text="{Binding SelectedDate, ElementName=CalendarControl}"
VerticalAlignment="Bottom"
HorizontalAlignment="Left" />
<Calendar x:Name="CalendarControl"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="Hidden" >
</Calendar>
答案 0 :(得分:1)
这可以通过将图像包装到Toggle按钮并将Calencar包装到Popup中来完成。将 ToggleButton 的 IsChecked 属性绑定到弹出的 IsOpen 属性。
<ToggleButton x:Name="btn">
<Image Name="imgCalendar" Width="20" Height="30" Source="/Images/Cal.jpg" />
</ToggleButton>
<TextBlock Text="{Binding SelectedDate, ElementName=CalendarControl}"
VerticalAlignment="Bottom"
HorizontalAlignment="Left" />
<Popup IsOpen="{Binding ElementName=btn, Path=IsChecked}" StaysOpen="False">
<Calendar x:Name="CalendarControl"
HorizontalAlignment="Center"
VerticalAlignment="Center">
</Calendar>
</Popup>