如何在WPF中水平放置3个文本项?
我有一个布局为WPF的应用程序,我应该水平放置3个文本项(以_Ch1、_Ch2、_Ch3结尾)。我是以一种你可以从所附图片中看到的方式来做的。如你所见,3个文本项位于水平区域的中心,但我需要以类似于3列的方式放置它们,第一个文本项应该移到左边,第二个文本项应该移到中间,第三个文本项应该移到右边 代码如下:如何在WPF中水平放置3个文本项?,wpf,Wpf,我有一个布局为WPF的应用程序,我应该水平放置3个文本项(以_Ch1、_Ch2、_Ch3结尾)。我是以一种你可以从所附图片中看到的方式来做的。如你所见,3个文本项位于水平区域的中心,但我需要以类似于3列的方式放置它们,第一个文本项应该移到左边,第二个文本项应该移到中间,第三个文本项应该移到右边 代码如下: <ItemsControl ItemsSource="{Binding SelectedEventPhotoList}"> <ItemsControl.ItemsP
<ItemsControl ItemsSource="{Binding SelectedEventPhotoList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
public List<string> SelectedEventPhotoList
{
get { return _selectedEventPhotoList; }
set
{
if (Equals(value, _selectedEventPhotoList))
return;
_selectedEventPhotoList = value;
RaisePropertyChanged(() => SelectedEventPhotoList);
}
}
公共列表已选择EventPhotoList
{
获取{return\u selectedEventPhotoList;}
设置
{
如果(等于(值,\ u选择EventPhotoList))
返回;
_selectedEventPhotoList=值;
RaiseProperty已更改(()=>SelectedEventPhotoList);
}
}
如何操作?尝试设置
ItemTemplate
:
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ItemsControl ItemsSource="{Binding SelectedEventPhotoList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center" Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
输出:
尝试设置
项目模板
:
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ItemsControl ItemsSource="{Binding SelectedEventPhotoList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center" Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
输出:
统一网格已经为您完成了这项工作,但是“项目”控件尚未拉伸研磨以填充其内容区域,请尝试将“水平内容对齐”设置为“拉伸”您的项目控件内部是什么,其内容对齐设置为什么?统一网格已经为您完成了这项工作,但是,items控件尚未拉伸研磨以填充其内容区域,请尝试将HorizontalContentAlignment设置为Stretch项目控件内部是什么,其内容对齐设置为什么?不需要“拉伸”。我需要将VerticalAlignment=“Center”添加到TextBlock,就这样。谢谢。不需要“拉伸”。我需要将VerticalAlignment=“Center”添加到TextBlock,就这样。谢谢