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:
为了开发自定义控件,我正在搜索DateTimePicker,但我找不到任何有用的信息。 LightSwitch的内置功能非常适合我的目的:
Can I use this control for my own purpose? If so, how? If not, are there any alternatives?
我可以将此控件用于我自己的目的吗?如果是这样,怎么样?如果没有,还有其他选择吗?
1 个解决方案
#1
1
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.
我能找到的最简单的方法是创建一个UserControl,然后在网格中并排放置一个DatePicker和一个TimePicker。
In the control's code-behind, declare two DateTime
variables that hold the desired data:
在控件的代码隐藏中,声明两个包含所需数据的DateTime变量:
public class MyControl
{
public DateTime MyDate { get; set; }
public DateTime MyTime { get; set; }
...
In the control's xaml, include these namespaces:
在控件的xaml中,包含以下命名空间:
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...
希望这有助于某人......
#1
1
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.
我能找到的最简单的方法是创建一个UserControl,然后在网格中并排放置一个DatePicker和一个TimePicker。
In the control's code-behind, declare two DateTime
variables that hold the desired data:
在控件的代码隐藏中,声明两个包含所需数据的DateTime变量:
public class MyControl
{
public DateTime MyDate { get; set; }
public DateTime MyTime { get; set; }
...
In the control's xaml, include these namespaces:
在控件的xaml中,包含以下命名空间:
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...
希望这有助于某人......