自定义日期选择器:如何更改图标图像并单击代码隐藏上的文本框打开弹出窗口?

问题描述 投票:0回答:1
c# wpf templates datepicker mahapps.metro
1个回答
0
投票

您始终可以为

Button
定义自定义模板,例如:

<customcontrols:CustomDatePicker x:Name="DataCreazione"
                                 SelectedDate="{Binding DataCreazione, StringFormat={}{0:dd/MM/yyyy}}"
                                 controls:TextBoxHelper.Watermark="Data Creazione"
                                 Cursor="Hand"
                                 BorderThickness="0"
                                 SelectedDateFormat="Short"
                                 Margin="0,0,0,0"
                                 Grid.ColumnSpan="3"
                                 Grid.Row="1" >
    <customcontrols:CustomDatePicker.Resources>
        <ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
            <Grid Background="Silver">
                <iconPacks:PackIconControl Kind="{x:Static iconPacks:PackIconFontAwesomeKind.CalendarAltSolid}"
                           Width="24"
                           Height="24" />
            </Grid>
        </ControlTemplate>
    </customcontrols:CustomDatePicker.Resources>
</customcontrols:CustomDatePicker>

if (Template.FindName("PART_Button", this) is Button button)
{
    button.Template = FindResource("ButtonTemplate") as ControlTemplate;
}
© www.soinside.com 2019 - 2024. All rights reserved.