質問

For developing a custom control, I'm in search of a DateTimePicker, and I could not find any useful info. LightSwitch's built-in one would be ideal for my purposes:

enter image description here
enter image description here enter image description here

Can I use this control for my own purpose? If so, how? If not, are there any alternatives?

役に立ちましたか?

解決

The easiest way I could find was to create a UserControl and then place a DatePicker and a TimePicker side by side in a grid.

In the control's code-behind, declare two DateTime variables that hold the desired data:

public class MyControl
{
    public DateTime MyDate { get; set; }
    public DateTime MyTime { get; set; }

    ...

In the control's xaml, include these namespaces:

xmlns:Ctls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:ImplCtls="clr-namespace:Microsoft.LightSwitch.Presentation.Implementation.Controls;assembly=Microsoft.LightSwitch.Client.Internal"

The control's definition:

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Ctls:DatePicker Grid.Row="0" Grid.Column="0"
                         SelectedDateFormat="Short"
                         SelectedDate="{Binding Path=MyDate, ElementName=MyUserControl, Mode=TwoWay}"/>
        <ImplCtls:BaseTimePicker Grid.Row="0" Grid.Column="1"
                                 Value="{Binding Path=MyTime, ElementName=MyUserControl, Mode=TwoWay}"/>
    </Grid>

Hope this helps out someone...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top