我的文本块宽度有问题。我的列表框中有一个很长的文本。问题是我的文字从右侧被弄坏了。请看看screenshot.help我。
我的示例代码在这里
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);
}
}
}
答案 0 :(得分:0)
只需从代码中删除MaxWidth
Height
和Width
,然后重试。
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);