Bonjour
Dans mon programme j'ai besoin de retourner une valeur d'un ItemControl TextBlock. Dans mon code XAML, j'ai l'événement MouseLeftButtonUp="Test" sur un TextBlock :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| <Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Plutus" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="Plutus.MainWindow"
Title="MainWindow" Height="523.725" Width="898" Background="#FF3A3939" WindowStartupLocation="CenterScreen" WindowState="Maximized">
<Window.Resources>
<Style TargetType="ScrollBar">
<Setter Property="Width" Value="35"/>
</Style>
</Window.Resources>
<ScrollViewer VerticalScrollBarVisibility="Auto" >
<ItemsControl x:Name="lvDataBinding" HorizontalContentAlignment="Stretch" BorderThickness="0" Margin="10" Grid.Row="3" Background="{x:Null}" ItemsSource="{Binding}" Foreground="White">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:CL_Operation}">
<Border BorderBrush="White" BorderThickness="1" CornerRadius="3" Margin="0,3" Grid.ColumnSpan="0" Background="Transparent" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid Width="{Binding strWidth}" Height="60" Background="Transparent" Margin="0,1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.05*" />
<ColumnDefinition Width="0.1*" />
<ColumnDefinition Width="0.1*" />
<ColumnDefinition Width="0.2*" />
<ColumnDefinition Width="0.1*" />
<ColumnDefinition Width="0.2*" />
<ColumnDefinition Width="0.1*" />
<ColumnDefinition Width="0.2*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<WrapPanel Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" Background="#FFFF8200">
<!-- <TextBlock Text="Customer" Foreground="#33B6EF" FontSize="20" />-->
<TextBlock Text="{Binding strPriorite}" FontSize="48" Foreground="Red" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" />
<TextBlock Text="{Binding strSsSect}" FontSize="10" Foreground="Black" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
</WrapPanel>
<WrapPanel Grid.Column="1" Grid.Row="0" Grid.RowSpan="3">
<!-- <TextBlock Text="Location" Foreground="#33B6EF" FontSize="20" />-->
<TextBlock Text="{Binding strRetardAvanceText}" FontSize="28" Foreground="{Binding scbColorRetardAvance}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" />
</WrapPanel>
<WrapPanel Grid.Column="2" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="2">
<WrapPanel.Style>
<Style TargetType="{x:Type WrapPanel}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="Gray"/>
</Trigger>
</Style.Triggers>
</Style>
</WrapPanel.Style>
<!-- <TextBlock Text="Created On" Foreground="#33B6EF" FontSize="20" />-->
<TextBlock Text="{Binding strNoOfOp}" FontSize="28" Foreground="White" FontWeight="Bold" MouseLeftButtonUp="Test"/>
</WrapPanel>
<WrapPanel Grid.Column="2" Grid.Row="2" Grid.ColumnSpan="3">
<!-- <TextBlock Text="Quantity" Foreground="#33B6EF" FontSize="20" /> -->
<TextBlock Text="{Binding strDescriptionOp}" FontSize="14" Foreground="White"/>
</WrapPanel>
<WrapPanel Grid.Column="4" Grid.Row="0">
<!-- <TextBlock Text="Created On" Foreground="#33B6EF" FontSize="20" />-->
<TextBlock Text="{Binding strNoArticle}" FontSize="14" Foreground="White"/>
</WrapPanel>
<WrapPanel Grid.Column="4" Grid.Row="1">
<!-- <TextBlock Text="Quantity" Foreground="#33B6EF" FontSize="20" /> -->
<TextBlock Text="{Binding strDateFormatee}" FontSize="14" Foreground="White"/>
</WrapPanel>
<WrapPanel Grid.Column="5" Grid.Row="0">
<!-- <TextBlock Text="Created On" Foreground="#33B6EF" FontSize="20" />-->
<TextBlock Text="{Binding strPcesPoste}" FontSize="14" Foreground="White"/>
</WrapPanel>
<WrapPanel Grid.Column="5" Grid.Row="1">
<!-- <TextBlock Text="Created On" Foreground="#33B6EF" FontSize="20" />-->
<TextBlock Text="{Binding strTpsPoste}" FontSize="14" Foreground="White"/>
</WrapPanel>
<WrapPanel Grid.Column="6" Grid.Row="0">
<!-- <TextBlock Text="Quantity" Foreground="#33B6EF" FontSize="20" /> -->
<TextBlock Text="{Binding strTempsPoste}" FontSize="14" Foreground="White"/>
</WrapPanel>
<WrapPanel Grid.Column="6" Grid.Row="1">
<!-- <TextBlock Text="Quantity" Foreground="#33B6EF" FontSize="20" /> -->
<TextBlock Text="{Binding strClient}" FontSize="14" Foreground="White"/>
</WrapPanel>
<WrapPanel Grid.Column="6" Grid.Row="2" Grid.ColumnSpan="2">
<!-- <TextBlock Text="Created On" Foreground="#33B6EF" FontSize="20" />-->
<!-- <TextBlock Text="Quantity" Foreground="#33B6EF" FontSize="20" /> -->
<TextBlock Text="{Binding strTypeOp}" FontSize="14" Foreground="White"/>
</WrapPanel>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
</Window> |
Ensuite en C# je peux retourner la valeur :
string str = (sender as TextBlock).Text;
Cependant, si je souhaite retourner la valeur d'un autre TextBlock de mon ItemControl du XAML, comment est-ce possible ?
OU mieux encore, est-il possible de retourner une valeur correspondant à ma ligne dans mon Binding, rempli avec this.DataContext = lstOperations;
Merci
Partager