Question
[Résolu] Evènement combobox WPF
- Marc
- Hors Ligne
- Membre premium
-
Réduire
Plus d'informations
- Messages : 90
- Remerciements reçus 0
il y a 8 ans 10 mois #23881
par Marc
Réponse de Marc sur le sujet Re:Evènement combobox WPF
Alors,
je n'ai pas chercher pour le binding de l'état des checkbox, je me doute que c'est possible, mais mon cerveau n'est pas prêt
Du coup en passant par un eventHandler ça marche.
Inspire toi de ça :
[code:1]
[xml]$xaml = @\"
<Window
xmlns=\"schemas.microsoft.com/winfx/2006/xaml/presentation\"
xmlns:«»x=\"schemas.microsoft.com/winfx/2006/xaml\"
x:Name=\"Window\" Title=\"Initial Window\" WindowStartupLocation = \"CenterScreen\"
Width = \"200\" Height = \"200\" ShowInTaskbar = \"True\">
<Grid>
<CheckBox x:Name=\"CheckBox1\" Content=\"CheckBox1\" HorizontalAlignment=\"Left\" Margin=\"10,58,0,0\" VerticalAlignment=\"Top\" IsEnabled=\"False\"/>
<CheckBox x:Name=\"CheckBox2\" Content=\"CheckBox2\" HorizontalAlignment=\"Left\" Margin=\"10,79,0,0\" VerticalAlignment=\"Top\" IsEnabled=\"False\"/>
<ComboBox x:Name=\"ComboBox1\" HorizontalAlignment=\"Left\" Margin=\"10,10,0,0\" VerticalAlignment=\"Top\" Width=\"120\">
<ComboBoxItem Content=\"CheckBox1\"/>
<ComboBoxItem Content=\"CheckBox2\"/>
</ComboBox>
</Grid>
</Window>
\"@
[System.Windows.Controls.SelectionChangedEventHandler]$SelectionChanged =
{
if($_.addedItems.Content -eq 'CheckBox1')
{
$CheckBox1.IsEnabled = $true
$CheckBox2.IsEnabled = $false
}
else
{
$CheckBox2.IsEnabled = $true
$CheckBox1.IsEnabled = $false
}
}
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$windows = [windows.markup.Xamlreader]::Load($reader)
$CheckBox1 = $windows.FindName(\"CheckBox1\"«»)
$CheckBox2 = $windows.FindName(\"CheckBox2\"«»)
$ComboBox1 = $windows.FindName(\"ComboBox1\"«»)
$ComboBox1.Add_SelectionChanged($SelectionChanged)
$windows.showdialog()
[/code:1]
Par contre si tu as plus de 2 checkbox ça devient lourd.
je n'ai pas chercher pour le binding de l'état des checkbox, je me doute que c'est possible, mais mon cerveau n'est pas prêt
Du coup en passant par un eventHandler ça marche.
Inspire toi de ça :
[code:1]
[xml]$xaml = @\"
<Window
xmlns=\"schemas.microsoft.com/winfx/2006/xaml/presentation\"
xmlns:«»x=\"schemas.microsoft.com/winfx/2006/xaml\"
x:Name=\"Window\" Title=\"Initial Window\" WindowStartupLocation = \"CenterScreen\"
Width = \"200\" Height = \"200\" ShowInTaskbar = \"True\">
<Grid>
<CheckBox x:Name=\"CheckBox1\" Content=\"CheckBox1\" HorizontalAlignment=\"Left\" Margin=\"10,58,0,0\" VerticalAlignment=\"Top\" IsEnabled=\"False\"/>
<CheckBox x:Name=\"CheckBox2\" Content=\"CheckBox2\" HorizontalAlignment=\"Left\" Margin=\"10,79,0,0\" VerticalAlignment=\"Top\" IsEnabled=\"False\"/>
<ComboBox x:Name=\"ComboBox1\" HorizontalAlignment=\"Left\" Margin=\"10,10,0,0\" VerticalAlignment=\"Top\" Width=\"120\">
<ComboBoxItem Content=\"CheckBox1\"/>
<ComboBoxItem Content=\"CheckBox2\"/>
</ComboBox>
</Grid>
</Window>
\"@
[System.Windows.Controls.SelectionChangedEventHandler]$SelectionChanged =
{
if($_.addedItems.Content -eq 'CheckBox1')
{
$CheckBox1.IsEnabled = $true
$CheckBox2.IsEnabled = $false
}
else
{
$CheckBox2.IsEnabled = $true
$CheckBox1.IsEnabled = $false
}
}
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$windows = [windows.markup.Xamlreader]::Load($reader)
$CheckBox1 = $windows.FindName(\"CheckBox1\"«»)
$CheckBox2 = $windows.FindName(\"CheckBox2\"«»)
$ComboBox1 = $windows.FindName(\"ComboBox1\"«»)
$ComboBox1.Add_SelectionChanged($SelectionChanged)
$windows.showdialog()
[/code:1]
Par contre si tu as plus de 2 checkbox ça devient lourd.
Connexion ou Créer un compte pour participer à la conversation.
- Marc
- Hors Ligne
- Membre premium
-
Réduire
Plus d'informations
- Messages : 90
- Remerciements reçus 0
il y a 8 ans 10 mois #23883
par Marc
Réponse de Marc sur le sujet Re:Evènement combobox WPF
Allé zou un truc plus propre ^^
[code:1]
[System.Windows.Controls.SelectionChangedEventHandler]$SelectionChanged =
{
[string]$SelectedItem = $_.addedItems.Content
foreach ($object in $windows.Content.Children)
{
if($object.Content -eq $SelectedItem)
{
$object.IsEnabled = $true
}
elseif ($object -is [System.Windows.Controls.Primitives.ToggleButton])
{
$object.IsEnabled = $false
}
}
}
[/code:1]
[code:1]
[System.Windows.Controls.SelectionChangedEventHandler]$SelectionChanged =
{
[string]$SelectedItem = $_.addedItems.Content
foreach ($object in $windows.Content.Children)
{
if($object.Content -eq $SelectedItem)
{
$object.IsEnabled = $true
}
elseif ($object -is [System.Windows.Controls.Primitives.ToggleButton])
{
$object.IsEnabled = $false
}
}
}
[/code:1]
Connexion ou Créer un compte pour participer à la conversation.
- Guillaume
- Auteur du sujet
- Hors Ligne
- Membre premium
-
Réduire
Plus d'informations
- Messages : 116
- Remerciements reçus 0
il y a 8 ans 10 mois #23886
par Guillaume
Réponse de Guillaume sur le sujet [Résolu] Evènement combobox WPF
Merci, ça fonctionne nickel !!
J'ai même pu l'adapter un peu pour modifier d'autres choses.
La première solution me convient mieux : j'active ou désactive plusieurs éléments selon le choix de la combobox.
Je repasse si j'ai un souci
La première solution me convient mieux : j'active ou désactive plusieurs éléments selon le choix de la combobox.
Je repasse si j'ai un souci
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.042 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- [Résolu] Evènement combobox WPF