xaml:
<Window x:Class="ReadAndVerify.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ReadAndVerify"
xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Background="#20201f" Foreground="White">
<Window.Resources>
<DataTemplate x:Key="ItemTemplate">
<ProgressBar Value="{Binding}" Width="100" Height="20"/>
</DataTemplate>
<DataTemplate x:Key="SelectedTemplate">
<TextBlock Text="{Binding Path=Title}" Foreground="White" />
</DataTemplate>
<Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle">
<Setter Property="ContentTemplate" Value="{StaticResource ItemTemplate}" />
</Style>
</Window.Resources>
<ListBox Name="lstCars" Margin="5" ItemContainerStyle="{StaticResource ContainerStyle}">
</ListBox>
</Window>
c#:
private List<Project> _projects = Project.GetProjects();
public MainWindow()
{
InitializeComponent();
lstCars.ItemsSource = _projects;
}
Project.cs:
[Serializable]
public class Project
{
[XmlIgnore]
private static string pathToFile = @"..\..\Xml\Project.xml";
public string Title { get; set; }
[XmlElement("StartDate")]
public DateTime StartDateForProject { get; set; }
[XmlElement("FinishDate")]
public DateTime FinishDateForProject { get; set; }
public Project() { }
public Project(string title,DateTime startDate, DateTime finishDate)
{
Title = title;
StartDateForProject = startDate;
FinishDateForProject = finishDate;
}
public override string ToString()
{
return "20";
}
}
Если вместо
{Binding}
написать 20 - то все хорошо. А так привязываться не хочет? Почему - не пойму. Помогите плиз.
Value
. Просто когда я вместо биндинг пишу в xaml коде значениеValue
, то все хорошо отображается. Так вот, как мне этоValue
вытянуть с объекта. – Виталий Шебаниц 13 окт '18 в 13:54