-1

不知何故 textwrap 不起作用。

我是 WPF 的新手,所以如果有人知道为什么这不起作用,我将不胜感激。

这是我的代码:

                <ItemsControl Grid.ColumnSpan="3" Grid.Row="1" Margin="0 0 0 0" ItemsSource="{Binding VRCItemsPaged}">
                    <ItemsControl.Template>
                        <ControlTemplate>
                            <StackPanel Orientation="Vertical">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="310"/>
                                        <ColumnDefinition Width="110"/>
                                        <ColumnDefinition Width="351"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Style="{StaticResource Label}" Grid.Column="0" Text="Description"/>
                                    <TextBlock Style="{StaticResource Label}" Grid.Column="1" Text="Code"/>
                                    <TextBlock Style="{StaticResource Label}" Grid.Column="2" Text="Value"/>
                                </Grid>
                                <StackPanel Orientation="Vertical" IsItemsHost="True"/>
                            </StackPanel>
                        </ControlTemplate>
                    </ItemsControl.Template>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid Height="Auto">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="280"/>
                                    <ColumnDefinition Width="30"></ColumnDefinition>
                                    <ColumnDefinition Width="80"/>
                                    <ColumnDefinition Width="30"></ColumnDefinition>
                                    <ColumnDefinition Width="351"/>
                                </Grid.ColumnDefinitions>
                                <TextBox FontWeight="Normal" TextWrapping="Wrap" IsEnabled="False" Grid.Column="0" Text="{Binding Path=Description}"/>
                                <TextBox FontWeight="Normal" Grid.Column="2" IsEnabled="False" Text="{Binding Path=Code}"/>
                                <TextBox FontWeight="Normal" Grid.Column="4" IsEnabled="False"    Text="{Binding Path=Value}"/>
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
4

1 回答 1

0

抱歉,这更像是另一个问题而不是答案,但我需要包含一个屏幕截图,这就是它不是评论的原因。

你的问题实际上没有用怎么办?我刚刚使用您的 ItemsControl XAML 创建了一个简单的测试窗口,并且我看到文本换行正确。

在此处输入图像描述

我使用的 XAML 是

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        Title="MainWindow" Height="350" Width="525">
    <ItemsControl Grid.ColumnSpan="3" Grid.Row="1" Margin="0 0 0 0" ItemsSource="{Binding Items}">
        <ItemsControl.Template>
            <ControlTemplate>
                <StackPanel Orientation="Vertical">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="310"/>
                            <ColumnDefinition Width="110"/>
                            <ColumnDefinition Width="351"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Text="Description"/>
                        <TextBlock Grid.Column="1" Text="Code"/>
                        <TextBlock Grid.Column="2" Text="Value"/>
                    </Grid>
                    <StackPanel Orientation="Vertical" IsItemsHost="True"/>
                </StackPanel>
            </ControlTemplate>
        </ItemsControl.Template>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid Height="Auto">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="280"/>
                        <ColumnDefinition Width="30"></ColumnDefinition>
                        <ColumnDefinition Width="80"/>
                        <ColumnDefinition Width="30"></ColumnDefinition>
                        <ColumnDefinition Width="351"/>
                    </Grid.ColumnDefinitions>
                    <TextBox FontWeight="Normal" TextWrapping="Wrap" IsEnabled="False" Grid.Column="0" Text="{Binding Path=Description}"/>
                    <TextBox FontWeight="Normal" Grid.Column="2" IsEnabled="False" Text="{Binding Path=Code}"/>
                    <TextBox FontWeight="Normal" Grid.Column="4" IsEnabled="False"    Text="{Binding Path=Value}"/>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Window>

后面的代码是。

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public ObservableCollection<TestObject> Items
        {
            get { return (ObservableCollection<TestObject>)GetValue(ItemsProperty); }
            set { SetValue(ItemsProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Items.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ItemsProperty =
            DependencyProperty.Register("Items", typeof(ObservableCollection<TestObject>), typeof(MainWindow), new PropertyMetadata(null));



        public MainWindow()
        {
            InitializeComponent();
            Items = new ObservableCollection<TestObject>();
            Items.Add(new TestObject() { Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." });
            Items.Add(new TestObject() { Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." });
        }
    }

    public class TestObject : DependencyObject
    {


        public string Description
        {
            get { return (string)GetValue(DescriptionProperty); }
            set { SetValue(DescriptionProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Description.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DescriptionProperty =
            DependencyProperty.Register("Description", typeof(string), typeof(TestObject), new PropertyMetadata(null));


    }
}
于 2012-11-23T11:29:33.067 回答