0

我的文本块宽度有问题。我的列表框中有一个长文本。问题是我的文本从右侧裁剪。请看一下截图。帮助我。

我的示例代码在这里

TextBlock tbl = new TextBlock();
tbl.Text = "Date : " + col.Value;
tbl.Width = 460;
tbl.MaxWidth = 460;
tbl.Height = 50;
tbl.Margin = new Thickness(35, 0, 0, 0);
tbl.TextWrapping = TextWrapping.Wrap;
tbl.TextAlignment = TextAlignment.Left;
tbl.Foreground = new SolidColorBrush(Color.FromArgb(255, 131, 72, 7));

LsUtsav.Items.Add(tbl);

在 Xaml 文件中

<controls:PanoramaItem x:Name="putsav" Header="Utsav">
            <controls:PanoramaItem.HeaderTemplate>
                <DataTemplate>
                    <TextBlock TextWrapping="Wrap" Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontSize="65" Margin="0,0,0,30" Foreground="#FF5F3D14" />
                </DataTemplate>
            </controls:PanoramaItem.HeaderTemplate>

            <ListBox Height="520" Margin="20,-50,9,34" Name="LsUtsav" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="#FF9E4E0E" FontSize="24" Width="460" >

            </ListBox>

            <!--Double line list with image placeholder and text wrapping-->

        </controls:PanoramaItem>

在此处输入图像描述

我解析 xml 文件并将其绑定到我的列表框中

XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);

            int d = xdoc.Descendants("KalyanPushti").Nodes().Count();
            //BtnFuture.Content = "Future (" + d + ")";
            putsav.Header = "Utsav (" + d + ")";
            LsUtsav.Items.Clear();
            if (d == 0)
            {
                LsUtsav.Items.Add("No Events");
            }
            else
            {
                LsUtsav.Items.Clear();
            //    BtnFuture.Content = "Future (" + d + ")";
                putsav.Header = "Utsav (" + d + ")";

                var summ = xdoc.Descendants("pushti");
                foreach (var col in summ.Elements())
                {
                    if (col.Name == "utsavlist")
                    {

                        TextBlock tbl = new TextBlock();
                        tbl.Text = col.Value;
                      //  tbl.FontFamily = new FontFamily("verdana");
                        tbl.Width = 470;

                        if (col.Value.Count() <= 35)
                        {
                            tbl.Height = 40;
                        }
                        else
                        {
                            tbl.Height = 80;
                        }
                        tbl.FontSize = 24;
                        tbl.Margin = new Thickness(35,0,0,0);
                        tbl.TextWrapping = TextWrapping.Wrap;
                        tbl.TextAlignment = TextAlignment.Left;
                        tbl.Foreground = new SolidColorBrush(Color.FromArgb(255, 131, 17, 17));
                        LsUtsav.Items.Add(tbl);
                    }
                    else if (col.Name == "date")
                    {
                        TextBlock tbl = new TextBlock();
                        tbl.Text = "Date : " + col.Value;
                        tbl.Width = 460;
                        tbl.MaxWidth = 460;
                        tbl.Height = 50;
                        tbl.Margin = new Thickness(35, 0, 0, 0);
                        tbl.TextWrapping = TextWrapping.Wrap;
                        tbl.TextAlignment = TextAlignment.Left;
                        LsUtsav.Foreground = new SolidColorBrush(Color.FromArgb(255, 131, 72, 7));


                        LsUtsav.Items.Add(tbl);



                    }
                    else
                    {
                        TextBlock tbl = new TextBlock();
                        tbl.Text = col.Value;
                        tbl.Width = 460;
                        tbl.Margin = new Thickness(35, 0, 0, 0);
                        tbl.TextWrapping = TextWrapping.Wrap;
                        tbl.TextAlignment = TextAlignment.Left;
                        LsUtsav.Foreground = new SolidColorBrush(Color.FromArgb(255, 131, 72, 7));
                        LsUtsav.Items.Add(tbl);

                    }

                }

            }
4

1 回答 1

0

只需从您的代码中删除MaxWidth HeightandWidth并重试。

TextBlock tbl = new TextBlock();
tbl.Text = "Date : " + col.Value;
tbl.Height = 100;
tbl.Width = 400;
tbl.Margin = new Thickness(35, 0, 0, 0);
tbl.TextWrapping = TextWrapping.Wrap;
tbl.TextAlignment = TextAlignment.Left;
LsUtsav.Foreground = new SolidColorBrush(Color.FromArgb(255, 131, 72, 7));
Mylist.Items.Add(tbl);
于 2013-09-28T05:54:50.080 回答