wpftoolkit
wpftoolkit copied to clipboard
DateTimePicker Name property
How can I select between 4 different DateTimePicker fields in powershell WPF if there is no Name property?
Hi, Can you be more precise please ? What do you mean by DateTimePicker fields ? What do you mean by PowerShell WPF ? You are not developing in with Visual Studio ? What "Name" property are you referring to ? Can you submit a sample project ?
Thank you.
Add-Type -assemblyName PresentationFramework Add-Type -assemblyName PresentationCore Add-Type -assemblyName WindowsBase Add-Type -Path "C:\temp\Extended.WPF.Toolkit.Binaries.NET.4.x\Xceed.Wpf.Toolkit.dll"
[xml]$xaml = @" <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
Title="Sharepoint notification:" Height="221.371" Width="375.925" ResizeMode="NoResize">
<Grid Height="287" VerticalAlignment="Top">
<Button Name="set" Content="Set" HorizontalAlignment="Left" Height="23" Margin="222,155,0,0" VerticalAlignment="Top" Width="139"/>
<xctk:DateTimePicker Height="23.333" Margin="85.667,34,10,0" VerticalAlignment="Top"/>
<xctk:DateTimePicker Height="23.333" Margin="85.667,62.333,10,0" VerticalAlignment="Top"/>
<TextBlock Name="notification_from" HorizontalAlignment="Left" Height="23.333" Margin="10,34,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="70.667"><Run Text="Tea"/><Run Text="d"/><Run Text="e "/><Run Text="from"/><Run Text=":"/></TextBlock>
<TextBlock Name="notification_to" HorizontalAlignment="Left" Height="23.333" Margin="10,62.333,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="70.667"><Run Text="Tea"/><Run Text="d"/><Run Text="e "/><Run Text="kuni"/><Run Text=":"/></TextBlock>
</Grid>
"@
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {Set-Variable -Name ($_.Name) -Value $Window.FindName($_.Name)}
$set.Add_Click({
Do stuff
})
$reader = (New-Object System.Xml.XmlNodeReader $xaml) $Window = [Windows.Markup.XamlReader]::Load($reader) $async = $window.Dispatcher.InvokeAsync({ $window.ShowDialog() | Out-Null }) $async.Wait() | Out-Null
Insert code did not work very well. Using the Name property I can map it as a variable and use a specific Item. DateTimePicker does not have that.
Hi, Can you use "x:Name" like we normally do in WPF/XAML ?
The "Name" property is valid for all FrameworkElement and DateTimePicker is a FrameworkElement.
Hi,
It works that way. Would be nice to update the documentation and examples.
Thanks, Ed