简体   繁体   English

如何在WPF中水平放置3个文本项?

[英]How to position 3 text items horizontally in WPF?

I have WPF application with layout where I should put 3 text items (ends with _Ch1, _Ch2, _Ch3) horizontally. 我有WPF应用程序的布局,我应该水平放置3个文本项(以_Ch1,_Ch2,_Ch3结尾)。 I did it in a way you could see in a picture attached. 我以一种你可以在附图中看到的方式做到了。 As you can see, the 3 text items are in the center of horizontal area, but I need to put them in a way that is similar to 3 columns that is first text item should be moved to left, second one should leave in the center, and third one should be moved to right. 正如您所看到的,3个文本项位于水平区域的中心,但是我需要将它们放置在类似于3列的方式中,即第一个文本项应该向左移动,第二个应该在中心,第三个应该向右移动。

在此输入图像描述

The code is as following: 代码如下:

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

How to do it? 怎么做?

Try setting the ItemTemplate : 尝试设置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>

Output: 输出:

产量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM