<ItemsControl>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Text}" Foreground="{Binding ForeColor}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
private List<System.DayOfWeek> _dayWeeks = new List<System.DayOfWeek>();
public List<System.DayOfWeek> DayWeeks
{
get{return _dayWeeks;}
}
public bool HasMonday
{
get{ return _dayWeeks.Any(d => d == DayOfWeek.Monday);}
set
{
if(value && !HasMonday)
{
_dayWeeks.Add(DayOfWeek.Monday);
OnPropertyChanged("DayWeeks");
OnPropertyChanged("HasMonday");
}
if(!value && HasMonday)
{
_dayWeeks.Remove(DayOfWeek.Monday);
OnPropertyChanged("DayWeeks");
OnPropertyChanged("HasMonday");
}
}
}
// Дальше аналогично для других дней недели
class A
{
public string Name{get;set;}
public A Parent {get;set;}
public IEnumerable<A> Children
{
get
{
return AllItemsOfA.Select(a => a.Parent == this);
}
}
public int Level()
{
int level = 0;
var current = Parent;
while(current != null)
{
current = current.Parent;
level ++;
}
return level;
}
}
comboBox2.SelectedIndex = (comboBox2.ItemsSource as System.Data.DataView).IndexOf("Вася");
comboBox2.SelectedItem = (comboBox2.ItemsSource as System.Data.DataView).Find("Вася");
using System;
class Program
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Starting WpfApplication1.exe...");
var domain = AppDomain.CreateDomain("WpfApplication1Domain");
try
{
domain.ExecuteAssembly("WpfApplication1.exe");
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
AppDomain.Unload(domain);
}
Console.WriteLine("WpfApplication1.exe exited, exiting now.");
}
}
public class Worker
{
public string FIO {get;set;}
public SpanTime WorkTime {get;set;}
}
<ListBox x:Name="lst">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text="{Binding FIO}" />
<TextBox Text="{Binding WorkTime}" Grid.Column="1"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
lst.ItemSource = new List<Worker>() {new Worker(){FIO = "Иванов"}, new Worker(){FIO = "Петров"}};
class Item
{
public string Name {get;set;}
public IEnumerable<Item> Children
{
get {/* тут код получения из базы подчинённых элементов*/}
}
}
<TreeView>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
<Window ...>
<Window.DataContext>
<game:Game/>
</Window.DataContext>
<StackPanel>
<local:MageControl DataContext="{Binding Red}"/> <!-- привязка к DataContext отлично работает -->
<local:MageControl DataContext="{Binding Blue}" Turn="{Binding Turn}"/> <!-- привязка к Turn не работает! -->
</StackPanel>
</Window>