I am trying to bind a list of objects to a list of HyperLinks
that are com开发者_如何学运维ma-separated, and clickable.
I can do it if it's only one of them per cell, but I don't know how to bind a collection per cell.
Something like this in a single GridViewColumn
cell:
Effect01, Effect02, Effect02, Shader01. Shader02
where clicking any of them will call the binded object's Execute
method.
Each element is:
public class EffectLink : IExecutable
{
public string Name {get; set;}
public void Execute ();
}
as enforced by IExecutable
.
I do it this way because the behaviour of Execute
will depend on whether it's a shader, an effect, etc.
Any ideas?
EDIT:
I found that I could do this:
<TextBlock>
<Hyperlink>Effect01</Hyperlink>
<Hyperlink>Effect02</Hyperlink>
</TextBlock>
So this shows 2 space-separate hyperlinks in a single cell.
Also this question might be related, but it shows how do it in code, not xaml: Nested TextBlocks and Hyperlinks, How do you replicate this XAML in C#?
put an ItemsControl
in your GridViewColumn.CellTemplate
<GridViewColumn >
<GridViewColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="commaTextBlock" Text=", " />
<TextBlock><Hyperlink><Run Text="{Binding Path=Name}" /></Hyperlink></TextBlock>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
<Setter Property="Visibility" TargetName="commaTextBlock" Value="Collapsed"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
精彩评论