C# 如何创建带有链接的DataTemplate
我正在尝试为(PropertyDescriptors的)PropertyCollection创建数据模板,以此格式显示集合中的项 描述符1>描述符2>描述符3>描述符4>描述符5 每个描述符都是一个链接(使用超链接),我的问题是我可以用标签(不是ItemsControl主机)来实现吗?如果是的话,谁能给我一个关于如何用DataTemplates实现这一点的例子 另外,是否仍然可以从DataTemplate访问属性描述符?例如,假设我想使用属性描述符的当前实例作为CommandParameterC# 如何创建带有链接的DataTemplate,c#,.net,wpf,xaml,datatemplate,C#,.net,Wpf,Xaml,Datatemplate,我正在尝试为(PropertyDescriptors的)PropertyCollection创建数据模板,以此格式显示集合中的项 描述符1>描述符2>描述符3>描述符4>描述符5 每个描述符都是一个链接(使用超链接),我的问题是我可以用标签(不是ItemsControl主机)来实现吗?如果是的话,谁能给我一个关于如何用DataTemplates实现这一点的例子 另外,是否仍然可以从DataTemplate访问属性描述符?例如,假设我想使用属性描述符的当前实例作为CommandParameter
感谢您的帮助。您可以尝试使用一个带有ItemsPanel的列表框来实现这一点,该列表框对项目使用水平布局(在我的示例中,我只是绑定到一个字符串列表)。嗯 代码:
公共列表属性{get;set;}
XAML:
<ListBox ItemsSource="{Binding Properties}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}"
MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink NavigateUri="{Binding}">
<TextBlock Text="{Binding StringFormat={}{0} >}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
截图:
<ListBox ItemsSource="{Binding Properties}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}"
MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink NavigateUri="{Binding}">
<TextBlock Text="{Binding StringFormat={}{0} >}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>