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 105 106
|
<Window x:Class="WpfListBoxItemEvent.ListBoxSwitchItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfListBoxItemEvent"
Title="SwitchItem With ToggleButton" Height="300" Width="300">
<Window.Resources>
<local:Cards x:Key="myDataSource"></local:Cards>
<local:BoolToVisibilityConverter x:Key="boolToVis" />
<!-- Fill Brushes -->
<LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="#CCC" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<!-- Border Brushes -->
<LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#CCC" Offset="0.0"/>
<GradientStop Color="#444" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<DataTemplate
x:Key="CardTemplate"
DataType="{x:Type local:Card}">
<Border Background="Transparent"
BorderBrush="DarkGray"
BorderThickness="0,0,0,0"
Padding="2">
<StackPanel
Orientation="Horizontal" >
<!-- Contenu d'une carte -->
<Grid
Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Name="TextBlockCard"
Text="{Binding text}"
FontSize="16"
Background="LightBlue"
Visibility="{Binding ElementName=ToggleEditMode,
Path=IsChecked,
Converter={StaticResource boolToVis},ConverterParameter=False }">
</TextBlock>
<TextBox
Grid.Column="0"
Name="TextBockCard"
Text="{Binding text}"
FontSize="16"
Background="Black"
Foreground="Red"
Visibility="{Binding ElementName=ToggleEditMode,
Path=IsChecked,
Converter={StaticResource boolToVis},ConverterParameter=True}">
</TextBox>
</Grid>
<!--toggle button deguise en bouton-->
<ToggleButton
x:Name ="ToggleEditMode"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
IsChecked="False" >
<ToggleButton.Template>
<ControlTemplate
TargetType="ToggleButton">
<Border
BorderThickness="1"
BorderBrush="{StaticResource NormalBorderBrush}"
CornerRadius="2"
Padding="5"
Background="{StaticResource NormalBrush}" >
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text ="ClickEdit">
</TextBlock >
</Border>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
</StackPanel>
</Border>
</DataTemplate>
</Window.Resources>
<StackPanel>
<ListBox
Height="200"
ItemTemplate="{StaticResource CardTemplate}"
ItemsSource="{StaticResource myDataSource}">
</ListBox>
</StackPanel>
</Window> |
Partager