Здравствуйте, подскажите пожалуйста как правильно получить Binding'ом данные из
public class Street
{
public Street(string _Name, int _CarsVolume, int _CarsIn, int _CarsOut, int _Norma)
{
this.Name = _Name;
this.CarsVolume = _CarsVolume;
this.CarsIn = _CarsIn;
this.CarsOut = _CarsOut;
this.Norma = _Norma;
Color color;
}
public string Name { get; set; }
public int CarsVolume {get {return CarsVolume;} set {if (CarsVolume > 50) this.color = Colors.Red; else this.color = Colors.Green; } }
public int CarsIn { get; set; }
public int CarsOut { get; set; }
public int Norma { get; set; }
public Color color { get; set; }
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Street[] streets =
{
new Street("Moskovskiy prospect", 500, 30, 40, 400)
};}}
Здравствуйте, RedName, Вы писали:
RN>Здравствуйте, подскажите пожалуйста как правильно получить Binding'ом данные из
RN>RN> public class Street
RN> {
RN> public Street(string _Name, int _CarsVolume, int _CarsIn, int _CarsOut, int _Norma)
RN> {
RN> this.Name = _Name;
RN> this.CarsVolume = _CarsVolume;
RN> this.CarsIn = _CarsIn;
RN> this.CarsOut = _CarsOut;
RN> this.Norma = _Norma;
RN> Color color;
RN> }
RN> public string Name { get; set; }
RN> public int CarsVolume {get {return CarsVolume;} set {if (CarsVolume > 50) this.color = Colors.Red; else this.color = Colors.Green; } }
RN> public int CarsIn { get; set; }
RN> public int CarsOut { get; set; }
RN> public int Norma { get; set; }
RN> public Color color { get; set; }
RN> }
RN> public partial class MainWindow : Window
{
ObservableCollection<Street> streets = new ObservableCollection<Street>();
public ObservableCollection<Street> GameCollection { get { return streets; } }
RN> public MainWindow()
RN> {
RN> InitializeComponent();
streets.Add(
new Street("Moskovskiy prospect", 500, 30, 40, 400)
);
RN>
<Window ...
DataContext="{Binding RelativeSource={RelativeSource Self}}"
>
<!--http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1-->
<ListView ItemsSource="{Binding GameCollection}" Grid.Row="0" Grid.Column="0" Margin="5" Grid.ColumnSpan="2"
HorizontalAlignment="Center" Background="LightGray"
VerticalAlignment="Top">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="CarsVolume" DisplayMemberBinding="{Binding CarsVolume}" />
<GridViewColumn Header="CarsIn" DisplayMemberBinding="{Binding CarsIn}" />
...
</GridView>
</ListView.View>
</ListView>
</Window>
для порядка, неплохо бы еще, чтобы класс Street реализовывал INotifyPropertyChanged. При этом, если обновление на лету не нужно, то собственно событие можно и не дергать, но для системы байндинга это будет существенным облегчением.