Je suit UserControl:comment lier propriété spécifique au contrôle de l'utilisateur dans ItemsControl
<Grid x:Name="LayoutRoot">
<CheckBox x:Name="seat" Margin="2,2,2,2.901" BorderBrush="#FF003FFF" Content="{Binding Path=TypeSSeat, ElementName=UserControl}" />
</Grid>
Avec ce CodeBehind:
[DefaultValue(Nothing)]
public enum TypeSeat
{
Nothing,FirstClass, businessclass , economyclass ,NoSeat
}
public partial class UCSeat : UserControl
{
public TypeSeat TypeSSeat
{
get
{
return (TypeSeat)GetValue(ItemTextProperty);
}
set
{
SetValue(ItemTextProperty, value);
}
}
public static readonly DependencyProperty ItemTextProperty =
DependencyProperty.Register("TypeSSeat", typeof(TypeSeat), typeof(UCSeat), new PropertyMetadata(default(TypeSeat)));
je veux ItemsControl remplir cette usercontrol mais après cours j'ai juste un checkBox.
ceci est mon code windows:
<ItemsControl Name="icName" Height="366" VerticalAlignment="Top" ItemsSource="{Binding Path=UCSeat}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="0,0,0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<local:UCSeat HorizontalAlignment="Left" Width="156.8" TypeSSeat="{Binding seat1}" ToolTip="1"/>
<local:UCSeat HorizontalAlignment="Left" Width="156.8" TypeSSeat="{Binding seat2}" ToolTip="2"/>
et avec ce code derrière:
List<SeatList> lst = new List<SeatList>();
lst.Add(new SeatList { seat1 = TypeSeat.FirstClass, seat2 = TypeSeat.FirstClass, seat3 = TypeSeat.NoSeat, seat4 = TypeSeat.FirstClass, seat5 = TypeSeat.FirstClass, seat6 = TypeSeat.Nothing, seat7 = TypeSeat.Nothing, seat8 = TypeSeat.Nothing, seat9 = TypeSeat.Nothing, seat10 = TypeSeat.Nothing, seat11 = TypeSeat.Nothing, seat12 = TypeSeat.Nothing, seat13 = TypeSeat.Nothing, seat14 = TypeSeat.Nothing });
icName.ItemsSource = lst;
oh mon coup je l'ai oublié. Je vous remercie. –