It's possible to show/hide and enable/disable controls via PowerShell code.
For example, you can show/hide or enable/disable controls for certain file types, or depending on the value of another property.
The controls can be manipulated at any time in the PowerShell code. Access these controls via the function $dsWindow.FindName("thenameofyourcontrol")
. A prerequisite for this capaibility is that your control exposes an attribute Name with a unique name.
For this example, we will disable the Title textbox when editing a file. The TextBox for the property title will get the Name txtTitle
, like this:
<TextBox Name="txttitle" ....
Inside the InitializeWindow
, we will check whether the dialog is a file dialog and if it's in edit mode.
function InitializeWindow
{
$dialogName = $dsWindow.DataContext.GetType().Name
if($dialogname--eq-"fileviewmodel"--and-$dswindow.name--eq-"filewindow")
{
$dsWindow.FindName("txttitle").IsEnabled=$false
}
}
As you can see, with FindName("nameofthecontrol")
, we can access the IsEnabled
property, or all of the other properties that this type of control might offer.
The same technique can be applied within event handlers to influence the behavior of each control while the user is entering data.
CAD Example
In the case of CAD, the syntax is the same except for the check whether the dialog is in create or edit mode.
Inside the InitializeWindow
we check whether the dialog is a file dialog and if it's in edit mode:
function InitializeWindow
{
$dialogName = $dsWindow.DataContext.GetType().Name
if($Prop["_EditMode"].Value -eq $true)
{
$dsWindow.FindName("txttitle").IsEnabled=$false
}
}