Windows Phone 7
[wp7] 유동적인 Button 에서 Template 입히기
동동(이재동)
2010. 7. 9. 16:38
유동적인 Button에서 Template를 입혀보자
foreach (var item in _appBoxModel.GetFavoriteListFromFile())
{
Button favoriteButton = new Button()
{
Content = item.Name,
DataContext = item,
Width = 150,
Height = 150,
FontSize = 15,
Template = this.Resources["xControl"] as ControlTemplate,
Style = Application.Current.Resources[item.Style] as Style
};
일단 유동적으로 만들어질 버튼에 templete을 지정하고
xaml에
<phoneNavigation:PhoneApplicationPage.Resources>
<ControlTemplate x:Name="xControl" TargetType="Button" >
<StackPanel>
<StackPanel>
<Image Source="{Binding Image}" Width="100" Height="100" />
</StackPanel>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center"/>
</StackPanel>
</ControlTemplate>
</phoneNavigation:PhoneApplicationPage.Resources>
이렇게 리소스로 넣으면 된다~ 바인딩 데이터는 dataContext로~