Tuesday, August 28, 2012

How to attach the Content Control to the listbox? [closed]

How to attach the Content Control to the listbox? [closed]

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;         }     } } 

No Answer and comments so far




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog