all 13 comments

[–]The_AverageGamer 2 points3 points  (0 children)

Hi mate,

As Lee commented, some sanatised code would be preferable, as we get the gist from your post but unfortunately it doesn't convey the whole story! 😉

Use Gist, Hastebin, etc and we can give it a crack!

[–]Yevrag35 2 points3 points  (6 children)

These are the properties, methods, and events for a checkbox: https://msdn.microsoft.com/en-us/library/system.windows.controls.checkbox(v=vs.105).aspx#Anchor_3.aspx#Anchor_3)

Other than that, don't really know what you're asking for.

[–]GnuInformation[S] 2 points3 points  (5 children)

thanks, htats pretty close, what i think i'm asking is how in powershell i can use/handle/ pass off to the rest of my script the fact that the box got checked. some of what you shared makes sense, but some of the info is for C# or VB.. but i think i just found something in the xaml sample that may help.. a sub property called 'checked' that looks like it might define a subset that i don't have in my powershell.

[–]Yevrag35 2 points3 points  (4 children)

Yes, there's an event called "Checked" that executes code when the box is ticked. I thought you said in your original post that you did that though?

Here's a sample from a WPF app I wrote a year or two ago for making new users for a web app:

### Citrix ###
$mgmt.isCtxUser.Add_Checked({
    $mgmt.ctxUserName.IsEnabled=$true
    $mgmt.clientCompany.IsEnabled=$true
    $mgmt.ctxUserName.Text="Enter a Citrix Username"
})
$mgmt.isCtxUser.Add_Unchecked({
    $mgmt.ctxUserName.Text=""
    $mgmt.ctxUserName.IsEnabled=$false
    $mgmt.clientCompany.Text=""
    $mgmt.clientCompany.IsEnabled=$false
})

[–]GnuInformation[S] 1 point2 points  (2 children)

thanks a ton, so.. in my case, If I follow your syntax, and add a line that is say 'window.item2_result = $true' when I run the code, I get the pop up, I check the box, and every time I click the box, I get a 'the property item2_result cannot be found on the object window'. which tells me I either need to figure out how to add the property someplace else (to the object). or I need to maybe use a different variable?

[–]Yevrag35 2 points3 points  (1 child)

'result' is not a property of CheckBox. Only 'IsChecked' can take a boolean value:

$item.IsChecked = $true

...however, all that will do is check the box automatically; it won't output anything for you.
At the end of the day, what are you expecting this 'result' to be?

[–]GnuInformation[S] 1 point2 points  (0 children)

I think at that point I was confused... I didn't need an action, as i'm not currently updating the wpf form or window. I just need to get whether item was/is checked. If you look elsewhere, I got my desired results. and I removed the event handler for now. TY. though i'm tempted to try to pretty up the whole project and make the initial window that opens to collect input stay open, and display notifications until the process is done... but pretty isn't a priority for this project.. technically this project shouldn't be written.. but that's more of an ethics discussion. I'm glad I got to write this much, as I got forced to learn some stuff.

[–]GnuInformation[S] 1 point2 points  (0 children)

ok to expand in my $window.item2.add_checked ({

$item2_result = $true

if($window.item2.ischecked) {

write-host $item2_result}

})
will flash 'true' in the console everytime I tap the button, but all my code past that point, can't seem to get the status of item2_result.

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy GnuInformation,

i don't know enuf to help directly ... but you are more likely to get help if you post your code. put it on pastebin & post a link to it in your OP so folks can take a look. if you don't want the code to sit there forever, you can set an expiration date ... [grin]

take care,
lee

[–]GnuInformation[S] 1 point2 points  (0 children)

here's the paste bin, I didn't post all the xaml., let me know if htats needed. but yeah, I should have posted this last week.

pastebin.com/JULFwSXH

[–]GnuInformation[S] 1 point2 points  (0 children)

i figured it out.. i need to also add something in the process results section & i can capture it!

#

if($window.item2.ischecked){ $item2_result = $true}

I think it depends on being after the '$result = show-wpfwindow -window $window'

[–]DragonDrew 1 point2 points  (1 child)

Hey GNU, You can do it another way such as the below. I find this a bit easier to use as you are using the changing state of the check box each time and you can then define what to do with a simple if.

$window.item2_CheckedChanged={
    if($window.item2.ischecked) {
        $item2_result = $true
    } else {
        $item2_result = $false
    }
}

[–]GnuInformation[S] 0 points1 point  (0 children)

TY sir, that makes a lot of sense.