Flash info

Prenez une longueur d'avance avec PowerShell. Faire ce choix c'est anticiper l'avenir des produits Microsoft mais aussi être plus performant dans son travail quotidien d'admin système.

 
Accueil arrow Forum

Bienvenue sur le forum PowerShell-Scripting.com

 
marcci
Utilisateur

PowerShelleur Amateur
Messages: 90
graphgraph
Karma: 10  
WPF-Listview template - 17/03/17 15:40 Bonjour a tous,
je continue mon exploration de WPF.

J'ai une listview avec des colonnes 'templaté' avec des textbox lié à un objet datatable.
Jusque la tout va bien.

Je souhaiterais pouvoir agir sur les events des textbox.
Malheureusement je ne sais pas comment les atteindre.

Voici un extrait de mon XAML.

Code:

  <ListView Name="Lstv_CheckPointResources" HorizontalAlignment="Left" Height="336" VerticalAlignment="Top" Width="788" SelectionMode="Extended" Margin="0,10,0,0" HorizontalContentAlignment="Center">                             <ListView.View>                                 <GridView>                                     <GridViewColumn Header="" Width="22">                                         <GridViewColumn.CellTemplate>                                             <DataTemplate>                                                 <StackPanel>                                                     <Ellipse Fill="DarkGreen" Stroke="Black" Height="10" Width="10" HorizontalAlignment="Center" VerticalAlignment="Center"/>                                                 </StackPanel>                                             </DataTemplate>                                         </GridViewColumn.CellTemplate>                                     </GridViewColumn>                                     <GridViewColumn Header="Server" Width="300">                                         <GridViewColumn.CellTemplate>                                             <DataTemplate>                                                 <StackPanel>                                                     <TextBox Text="{Binding 'Server'}" Width="300"/>                                                 </StackPanel>                                             </DataTemplate>                                         </GridViewColumn.CellTemplate>                                     </GridViewColumn>                                     <GridViewColumn Header="Lan" Width="160">                                         <GridViewColumn.CellTemplate>                                             <DataTemplate>                                                 <StackPanel>                                                     <TextBox Text="{Binding 'Lan'}" Width="160"/>                                                 </StackPanel>                                             </DataTemplate>                                         </GridViewColumn.CellTemplate>                                     </GridViewColumn>                                     <GridViewColumn Header="Nat" Width="160">                                         <GridViewColumn.CellTemplate>                                             <DataTemplate>                                                 <StackPanel>                                                     <TextBox Text="{Binding 'Nat'}" Width="160"/>                                                 </StackPanel>                                             </DataTemplate>                                         </GridViewColumn.CellTemplate>                                     </GridViewColumn>                                     <GridViewColumn Header="Port" Width="70">                                         <GridViewColumn.CellTemplate>                                             <DataTemplate>                                                 <StackPanel>                                                     <TextBox Text="{Binding 'Port'}" Width="70"/>                                                 </StackPanel>                                             </DataTemplate>                                         </GridViewColumn.CellTemplate>                                     </GridViewColumn>                                     <GridViewColumn Header="Protocol" Width="70">                                         <GridViewColumn.CellTemplate>                                             <DataTemplate>                                                 <StackPanel>                                                     <TextBox Text="{Binding 'Protocol'}" Width="70"/>                                                 </StackPanel>                                             </DataTemplate>                                         </GridViewColumn.CellTemplate>                                     </GridViewColumn>                                 </GridView>                             </ListView.View>                         </ListView>



La listview s'affiche correctement les textbox se remplisse avec la datatable.
Mais je ne peut pas dans mon code interagir avec les textbox.

Si besoin je poserais un code fonctionel.

Message édité par: marcci, à: 17/03/17 16:40
  | | L'administrateur a désactivé l'accés public en écriture.
marcci
Utilisateur

PowerShelleur Amateur
Messages: 90
graphgraph
Karma: 10  
Re:WPF-Listview template - 13/07/17 15:20 Bonjour,
après des heures de recherches et de bidouillage, j'ai enfin trouvé une solution à mon problème.
C'est laid, et aussi as been que Windows.form

Mais ça marche

source: http://www.c-sharpcorner.com/UploadFile/87b416/dynamically-adding-or-retrieves-templates-in-to- controls-in/

Code:

  [xml]$xaml = @" <Window     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     x:Name="Window" Title="Initial Window" WindowStartupLocation "CenterScreen"      Width "500" Height "400" ShowInTaskbar "True">     <Grid x:Name="GeneralGrid"/> </Window> "@ 


Code:

  $reader = (New-Object System.Xml.XmlNodeReader $xaml) $windows = [windows.markup.Xamlreader]::Load($reader) $GeneralGrid $windows.FindName('GeneralGrid') $colDefin 'Hello','ButtonNember','Upper' $Resources = New-Object System.Data.DataTable foreach($col in $colDefin){     [void]$Resources.Columns.Add($col) } [System.Windows.Controls.TextChangedEventHandler]$ToUpper =  {     $Event $_     $Resources.rows[[int32]($Event.Source.Name.Substring(1))].Upper $Event.Source.Text.ToUpper() } $GridView = New-Object System.Windows.Controls.GridView $GridViewColumn = New-Object System.Windows.Controls.GridViewColumn $GridViewColumn.Header 'Bouton' $GridViewColumn.Width 50 $DataTemplate = New-Object System.Windows.DataTemplate $button = new-object System.Windows.FrameworkElementFactory([System.Windows.Controls.Button]) $BindingNumber = New-Object System.Windows.Data.Binding("ButtonNember") $button.SetBinding([System.Windows.Controls.Button]::NameProperty,$BindingNumber) $button.SetValue([System.Windows.Controls.Button]::ContentProperty,'OK') $DataTemplate.VisualTree $button $GridViewColumn.CellTemplate $DataTemplate $GridView.Columns.Add($GridViewColumn) $GridViewColumn2 = New-Object System.Windows.Controls.GridViewColumn $GridViewColumn2.Header 'Data' $GridViewColumn2.Width 170 $DataTemplate2 = New-Object System.Windows.DataTemplate $TextBox = new-object System.Windows.FrameworkElementFactory([System.Windows.Controls.TextBox]) $Binding = New-Object System.Windows.Data.Binding("Hello") $BindingName = New-Object System.Windows.Data.Binding("ButtonNember") $TextBox.SetBinding([System.Windows.Controls.TextBox]::TextProperty,$Binding) $TextBox.SetBinding([System.Windows.Controls.TextBox]::NameProperty,$BindingName) $TextBox.SetValue([System.Windows.Controls.TextBox]::WidthProperty,150.00) $TextBox.AddHandler([System.Windows.Controls.TextBox]::TextChangedEvent,$ToUpper,$true) $DataTemplate2.VisualTree $TextBox $GridViewColumn2.CellTemplate $DataTemplate2 $GridView.Columns.Add($GridViewColumn2) $GridViewColumn3 = New-Object System.Windows.Controls.GridViewColumn $GridViewColumn3.Header 'ToUpper' $GridViewColumn3.Width 170 $DataTemplate3 = New-Object System.Windows.DataTemplate $TextBox1 = new-object System.Windows.FrameworkElementFactory([System.Windows.Controls.TextBox]) $BindingUP = New-Object System.Windows.Data.Binding("Upper") $TextBox1.SetBinding([System.Windows.Controls.TextBox]::TextProperty,$BindingUP) $TextBox1.SetValue([System.Windows.Controls.TextBox]::WidthProperty,150.00) $DataTemplate3.VisualTree $TextBox1 $GridViewColumn3.CellTemplate $DataTemplate3 $GridView.Columns.Add($GridViewColumn3) $LV = New-Object System.Windows.Controls.ListView $LV.Height 300 $LV.Width 475 $LV.Margin = New-Object System.Windows.Thickness(0,-50,0,0) $LV.view $GridView $LV.ItemsSource $Resources.DefaultView $GeneralGrid.Children.Add($LV) [void]$Resources.rows.Add('yes','n0',"") [void]$Resources.Rows.Add('no','n1',"") [void]$Resources.Rows.Add('Bonjour','n2',"") [void]$Resources.Rows.Add('Hello','n3',"") $windows.showdialog()|Out-Null



Message édité par: marcci, à: 14/07/17 11:04
  | | L'administrateur a désactivé l'accés public en écriture.
© 2020 PowerShell-Scripting.com