konto usunięte
Temat: Strona w Silverlight
Mam nadzieje, ze o to chodzilo:
<UserControl x:Class="SilverlightApplication1.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<UserControl.Resources>
<Style TargetType="TextBlock" x:Name="StylB" x:Key="StylBKey">
<Setter Property="Foreground" Value="Red"></Setter>
</Style>
<Style TargetType="ListBox" x:Key="StylA">
<Setter Property="Background" Value="Blue"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" Style="{StaticResource StylBKey}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<ListBox x:Name="myLB"
Style="{StaticResource StylA}"
ItemsSource="{Binding}">
</ListBox>
</Grid>
</UserControl>
No jeszcze mala klaska dla jasnosci:
public class Person
{
private String _name;
public String Name
{
get
{
return _name;
}
}
public Person()
{
_name = String.Empty;
}
public Person(String name)
: this()
{
_name = name;
}
}
No to potem jescze tylko w konstruktorze Page'a:
public partial class Page : UserControl
{
private ObservableCollection<Person> _personList;
public Page()
{
InitializeComponent();
_personList = new ObservableCollection<Person>()
{
new Person("Adam"), new Person("Wiola"), new Person("Ziutek")
};
DataContext = _personList;
}
}
Wiem, ze wkleilem troche nadmiarowo, ale ten konkretny kod dziala. Mozesz sobie po prostu skopiowac do projektu i kombinowac.
Have fun! ;)Karol Sotomski edytował(a) ten post dnia 14.04.09 o godzinie 18:00