-1

どういうわけかテキストラップが機能しません。

私は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 に答える