I`m trying to make a WPF application for a cinema, to book seats in a room. Here is what I did until now.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfControlLibrary1
{
public partial class SeatingArea : UserControl
{
public ObservableCollection<int> Seats { get; private set; }
public SeatingArea()
{
Seats = new ObservableCollection<int>();
for (int i = 1; i <= 200; i++)
Seats.Add(i);
InitializeComponent();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
MessageBox.Show(((FrameworkElement)sender).DataContext.ToString());
((Button)sender).Background = Brushes.Blue;
}
}
}
<UserControl x:Class="WpfControlLibrary1.SeatingArea"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Beige"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<StackPanel>
<TextBlock HorizontalAlignment="Center" Text="SEATING CHART" FontSize="24" Margin="0,10"/>
<ItemsControl ItemsSource="{Binding Seats}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Name="LayoutRoot">
<Button Name="Seat" Content="{Binding}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="30" Height="30" Margin="1,2" Click="Button_Click_1" />
</Grid>
<DataTemplate.Triggers>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Height="300" Width="550"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</UserControl>
As you can see I am using an user control for creating a seating chart. I am using buttons as seats.
My questions: How can I change the color of the seats or how to make them unclickable by their name in the C# code?

New Topic/Question
Reply



MultiQuote





|