WPF Question: Is this possible from mark up?

time to read 12 min | 2259 words

(Image from clipboard).png

"Categories:" is static text, the rest is generated via this code:

IAddChild c = Categories;//Categories is a Stack Panel with Horizontal Orientation

foreach (Category category in post.Categories)


      TextBlock block = new TextBlock();

      block.Text = category.Name;

      block.Style = (Style) FindResource("BigText");


      TextBlock seperator = new TextBlock();

      seperator.Text = "//";

      seperator.Style = (Style)FindResource("BigText");

      seperator.Foreground = Brushes.Brown;



Is there a way to do this via XAML and not from the code?

I would like to thank Tomas Restrepo for pointing me in the direct direction, this is indeed possible, like this:

<ItemsControl Name="Categories"




                  <WrapPanel Orientation="Horizontal"/>






                        <TextBlock Text="{Binding Path=Name}" Tag="{Binding Path=CategoryId}"


                                       Style="{StaticResource BigText}"/>

                        <TextBlock Text="//"


                                       Style="{StaticResource BigText}"/>





Notice the ItemsSource="{Binding}", which tripped me at first. Also, note that I am binding the tag of the text blog to the ID of the category. I don't really like this, but I couldn't figure out how to bind to the current item itself.