CalendarDayButtonStyle模板不支持TextBox

时间:2016-07-18 14:36:20

标签: c# wpf calendar

我想扩展WPF日历控件,以便为某些日期添加一些注释。

为此,我为CalendarDayButton创作了一种风格。

我面临的问题是我无法在CalendarDayButton Template属性中添加TextBox。我无法在TextBox中输入文字。

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApplication1"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Calendar>
        <Calendar.CalendarDayButtonStyle>
            <Style TargetType="CalendarDayButton">               
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <StackPanel>
                            <ContentPresenter x:Name="NormalText"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              Margin="5,1,5,1">
                                <TextElement.Foreground>
                                    <SolidColorBrush x:Name="selectedText"
                                                     Color="Red" />
                                </TextElement.Foreground>
                            </ContentPresenter>
                            <TextBox Text="Hi"></TextBox>
                            </StackPanel>

                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Calendar.CalendarDayButtonStyle>
    </Calendar>
</Grid>

0 个答案:

没有答案