0
XAML :콘텐츠 컨트롤을 목록 상자에 연결하는 방법은 무엇입니까?
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel >
<Grid Width="335" >
<TextBlock Text="{Binding Body}" />
</Grid>
</StackPanel>
</DataTemplate>
<DataTemplate >
<StackPanel >
<Grid Width="335" >
<Image Source="{Binding Image}" />
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
CS :
public class GardenConverter : ContentControl
{
public DataTemplate TextTemplate { get; set; }
public DataTemplate ImageTemplate { get; set; }
protected override void OnContentChanged(object oldContent, object newContent)
{
base.OnContentChanged(oldContent, newContent);
// apply the required template
GardenObject garden = newContent as GardenObject;
if (garden.image == "0")
{
ContentTemplate = TextTemplate;
}
else
{
ContentTemplate = ImageTemplate;
}
}
}
http://msdn.microsoft.com/en-us/library/system.windows.controls.datatemplateselector.aspx 참조 http://www.windowsphonegeek.com/articles/Implementing-Windows-Phone-7-DataTemplateSelector-and-CustomDataTemplateSelector – Newred