Question WinForms/WPF - Affichage

Plus d'informations
il y a 8 ans 10 mois #23944 par Guillaume
WinForms/WPF - Affichage a été créé par Guillaume
Je ne savais pas bien comment appeler ce topic mais vous allez comprendre ;)

Ci-dessous deux codes pour la même chose : un en WinForms, l'autre en WPF.
Le bouton sert juste à afficher 3 lignes de texte.

Sur le WinForms : la ligne 1 s'affiche, puis attente, puis ligne 2 s'affiche, puis attente, puis ligne 3 s'affiche.

Sur le WPF : attente, puis affichage total.

Comment faire pour que le WPF gère l'affichage comme le WinForms ?

Attention au smiley qui s'est inséré dans le code WPF !

WinForms
[code:1]$Cadre_Test = New-Object System.Windows.Forms.Form
$Cadre_Test.ControlBox = $True
$Cadre_Test.Text = \"Test\"
$Cadre_Test.Size = New-Object System.Drawing.Size(610,520)
$Cadre_Test.StartPosition = \"CenterScreen\"
$Cadre_Test.BackColor = 'White'
$Cadre_Test.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$Cadre_Test.Icon = [system.drawing.icon]::ExtractAssociatedIcon($PSHOME + \"\powershell.exe\"«»)
$Cadre_Test.Topmost = $True

$Champ_Versions = New-Object System.Windows.Forms.RichTextbox
$Champ_Versions.Location = New-Object System.Drawing.Point(10,10)
$Champ_Versions.Size = New-Object System.Drawing.Size(590,340)
$Champ_Versions.Multiline = $True
$Champ_Versions.Font = \"Régular,10\"
$Champ_Versions.ScrollBars = \"Vertical\"
$Champ_Versions.BackColor = 'FloralWhite'
$Champ_Versions.ReadOnly = $True
$Champ_Versions.Text = $Contenu_Versions
$Cadre_Test.Controls.Add($Champ_Versions)

$Bouton_Test = New-Object System.Windows.Forms.Button
$Bouton_Test.Location = New-Object System.Drawing.Point(200,400)
$Bouton_Test.Size = New-Object System.Drawing.Size(180,50)
$Bouton_Test.Text = \"Test\"
$Bouton_Test.Font = New-Object System.Drawing.Font(\"Calibri\",13,[System.Drawing.FontStyle]::Bold)
$Bouton_Test.Add_Click({ Test })
$Cadre_Test.Controls.Add($Bouton_Test)

Function Test {
$nl = \"`r`n\"
$Champ_Versions.AppendText(\"TITRE QUELCONQUE $nl $nl\"«») ; Start-Sleep -s 1
$Champ_Versions.AppendText(\"Action quelconque en cours... $nl\"«») ; Start-Sleep -Milliseconds 500
$Champ_Versions.AppendText(\"Action quelconque effectuée. $nl\"«»)
}


# AFFICHAGE CADRE
$Cadre_Test.Topmost = $False
[void] $Cadre_Test.ShowDialog()
[void] $Cadre_Test.Add_Shown({$Cadre_Test.Activate()})[/code:1]

WPF
[code:1][XML] $XAML = @\"
<Window Name=\"Test\"
xmlns=\"schemas.microsoft.com/winfx/2006/xaml/presentation\";
xmlns:«»x=\"schemas.microsoft.com/winfx/2006/xaml\";
Title=\"Test\" Height=\"650\" Width=\"520\" HorizontalAlignment=\"Center\" HorizontalContentAlignment=\"Center\" VerticalContentAlignment=\"Center\" VerticalAlignment=\"Center\" ResizeMode=\"CanMinimize\">
<Grid Margin=\"0\">
<Label Content=\"Résultats des actions :\" HorizontalAlignment=\"Left\" Margin=\"10,20,0,0\" VerticalAlignment=\"Top\" FontWeight=\"Bold\" Height=\"25\" Width=\"150\" Padding=\"5,2,5,5\" FontSize=\"14\"/>
<RichTextBox Name=\"Champ_Resultats\" HorizontalAlignment=\"Left\" Height=\"500\" Width=\"500\" Margin=\"10,50,0,0\" VerticalAlignment=\"Top\" FontWeight=\"Normal\" />
<Button Name=\"Bouton_Test\" Content=\"Test\" HorizontalAlignment=\"Left\" Margin=\"200,560,0,0\" VerticalAlignment=\"Top\" Width=\"75\" Height=\"32\" Background=\"#FFF0F0F0\" BorderBrush=\"#FFF0F0F0\"/>
</Grid>
</Window>
\"@


# CREATION DE L'INTERFACE GRAPHIQUE
$Affichage = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $XAML))

#VARIABLES
$Champ_Resultats = $Affichage.FindName(\"Champ_Resultats\"«»)
$Bouton_Test = $Affichage.FindName(\"Bouton_Test\"«»)

$Bouton_Test.Add_Click({Test})

Function Test {
$sl = \"`r`n\"
$rl = \"`r\"

$Champ_Resultats.AppendText(\"TITRE QUELCONQUE $sl\"«») ; Start-Sleep -s 1
$Champ_Resultats.AppendText(\"Action quelconque en cours... $rl\"«») ; Start-Sleep -s 1
$Champ_Resultats.AppendText(\"Action quelconque effectuée. $sl\"«»)
}


#=============================================#
# AFFICHAGE DE L'INTERFACE GRAPHIQUE #
#=============================================#

$Affichage.ShowDialog() | Out-Null[/code:1]

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 10 mois #23948 par Riblito
Réponse de Riblito sur le sujet Re:WinForms/WPF - Affichage
un exemple que je m'étais fais un jour,

je sais pas si ça va t'aider, car si j'ai bien compris tu arrives pas à afficher ta form en xaml ?

[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=\"Je suis une fenetre\" WindowStartupLocation = \"CenterScreen\"
Width = \"500\" Height = \"500\" ShowInTaskbar = \"true\">
</Window>
\"@

$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$windows = [windows.markup.Xamlreader]::Load($reader)

$windows.showdialog()[/code:1]<br><br>Message édité par: elemremy, à: 12/07/17 10:54

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 10 mois #23951 par Guillaume
Réponse de Guillaume sur le sujet Re:WinForms/WPF - Affichage
Non c'est l'affichage du texte dans la RichTextBox qui diffère.

Avec WinForms, ça suit le script.
Avec WPF, ça affiche tout d'un coup.

Je souhaiterais un moyen pour que WPF fonctionne dans ce cas comme WinForms ;)

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 10 mois #23965 par Guillaume
Réponse de Guillaume sur le sujet Re:WinForms/WPF - Affichage
Bonjour,

Je me permets juste de relancer ce topic.

S'il s'avère qu'il n'est pas possible que l'affichage de texte avec WPF n'est pas possible comme avec WinForms, je pense que je resterai avec WinForms.

Merci par avance ! :)

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 10 mois #23971 par Philippe
Réponse de Philippe sur le sujet Re:WinForms/WPF - Affichage
salut Guillaume_F

en faite il n'y a pas de refresh de prevue dans WPF d'apres ce que j'ai lu
mais il existe plusieurs solution

en voici une trouver sur ce site :
[code:1]Function Test {
$sl = \&quot;`r`n\&quot;
$rl = \&quot;`r\&quot;

$Champ_Resultats.AppendText(\&quot;TITRE QUELCONQUE $sl\&quot;)
$affichage.Dispatcher.Invoke([action]{$Champ_Resultats.AppendText(\&quot;\&quot;)},\&quot;render\&quot;)
Start-Sleep -s 1
#$Champ_Resultats.AppendText(\&quot;Action quelconque en cours... $rl\&quot;)
$affichage.Dispatcher.Invoke([action]{$Champ_Resultats.AppendText(\&quot;Action quelconque en cours 1... $rl\&quot;«»)},\&quot;render\&quot;)
Start-Sleep -s 1
$affichage.Dispatcher.Invoke([action]{$Champ_Resultats.AppendText(\&quot;Action quelconque en cours 2... $rl\&quot;)},\&quot;render\&quot;)
Start-Sleep -s 1
$affichage.Dispatcher.Invoke([action]{$Champ_Resultats.AppendText(\&quot;Action quelconque en cours 3... $rl\&quot;)},\&quot;render\&quot;)
Start-Sleep -s 1
$affichage.Dispatcher.Invoke([action]{ $Champ_Resultats.AppendText(\&quot;Action quelconque effectuée. $sl\&quot;) },\&quot;render\&quot;)
}[/code:1]<br><br>Message édité par: 6ratgus, à: 19/07/17 16:02

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 10 mois #23984 par Guillaume
Réponse de Guillaume sur le sujet Re:WinForms/WPF - Affichage
Super ! Merci beaucoup ! :cheer:

C'est un chouille plus lourd mais ça fonctionne très bien. Dommage en effet que ce ne soit pas natif. En espérant que ça change un jour ^^

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.045 secondes
Propulsé par Kunena